Base Time Limit: 1 second Space Limit: 131072 KB Score: 5Difficulty
: Level 1 Algorithm Question
Given an integer N, represent N as the sum of the squares of two integers ij (i <= j). If there are multiple representations, output them in increasing order of i.
For example: N = 130, 130 = 3^2 + 11^2 = 7^2 + 9^2 (Note: 3 11 and 11 3 count as one type)
Input
A number N (1 <= N <= 10^9)
Output
A total of K rows: 2 numbers in each row, i j, means N = i^2 + j^2 (0 <= i <= j). If it cannot be decomposed into the sum of squares of 2 numbers, output No Solution
Input example
130
Output example
3 11 7 9
#include<stdio.h> #include<math.h> #include<string.h> using namespace std; int force[10006]; intmain() { long long n; while(~scanf("%lld",&n)) { int flag=0; long long maxn=sqrt(n); for(long long i=0;i<=maxn;i++) { for(long long j=i;j<=maxn;j++) { if(i*i+j*j==n) { flag=1; printf("%lld %lld\n",i,j); break; } } } if(flag==0) printf("No Solution\n"); } return 0; }