Seeing 1e9 of the data basically excludes the possibility of violence. If a number can be represented by the sum of squares of two numbers, then these two numbers must not exceed his square root. So the basic idea is to first give the input of this number, reduce the amount of data, enumeration 0 to sqrt (number), and then to [0,sqrt (number)] This interval two to find whether there is such a number so that his square plus the previous enumeration of the sum of squares equals number. One thing to note is that the output is based on a small order in front of the number, and is going to be heavy. Based on the map container's one by one correspondence and internal automatic sorting, you can use the map container to do both of these tasks. The code is as follows:
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include < cstring> #include <cmath> #include <stack> #include <vector> #include <map> #include <set > #include <queue> #include <utility> #define LL long long#define Ull_ unsigned long longusing namespace std; int n; int searh_binary (int begin_, int end_, int num) {int L = begin_, r = end_; while (L < r) {int mid = (L + r) >> 1; int Index_one = mid * mid; int index_two = num * num; if (index_one + index_two = = N) {return mid; }else if (Index_one + Index_two < n) {L = mid + 1; }else{r = Mid; }} return-1;} int main () {CIN >> n; int num = (int) sqrt (n); int index; BOOL check = FALSE; Map<int, int> Map_; for (int i = 0; I <= num; i + +) {index = searh_binary (0, num, i);if (Index! =-1) {map_[min (I, index)] = max (i, index); Check = true; }} if (!check) {cout << "No solution" << Endl; }else{Map<int, int>::iterator it; for (it = Map_.begin (); It! = Map_.end (); it + +) {cout << it->first << "" << it->s Econd << Endl; }} return 0;}
51Nod 10,802 number of squares and