Base time limit: 1 seconds space limit: 131072 KB Score: 5 Difficulty: 1-level algorithm problem
Given an integer n, the n is represented as the sum of squares of 2 integers i J (i <= J), and if there are multiple representations, it is output in ascending order of I. For example: N = 130,130 = 3^2 + 11^2 = 7^2 + 9^2 (Note: 3 11 with 11 3 count 1 kinds) Input
A number n (1 <= n <= 10^9)
Output
A total of k rows: 2 numbers per line, I j, indicating n = i^2 + j^2 (0 <= i <= j). Output no solution if it cannot be decomposed to a sum of 2 numbers
Input example
130
Output example
3 117 9
Simple math problem began without brain violence T got a pitch,
Meow meow meow??? Just card me a set of data??? Frighten me hurriedly spent five nod shield to write a special sentence ...
Bah! You acmer face still need!!
We can set t^2=n, then we can see that I and J must be no more than T, so we traverse to sqrt (n),
Of course, we can not have no brain traversal, when we know I can be j^2= (n-i^2) to obtain J, in addition, I will not be greater than J.
The AC code is attached:
1#include <iostream>2#include <cmath>3 using namespacestd;4 5 intMain () {6 intN;7Cin>>N;8 intans=0;9 intt=sqrt (n);Ten for(intI=0; i<=t;i++){ One intJ=SQRT (n-i*i); A if(j*j+i*i==n&&j>=i) { -ans++; -cout<<i<<" "<<j<<Endl; the } - } - if(ans==0) -cout<<"No Solution"<<Endl; + return 0; -}
Sum of squares of 10,802 numbers