R (N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 1637 Accepted Submission (s ): 853 Problem DescriptionWe know that some positive integer x can be expressed as x = A ^ 2 + B ^ 2 (A, B are integers ). take x = 10 for example, 10 = (-3) ^ 2 + 1 ^ 2.We define R (N) (N is positive) to be the total number of variable presentation of N. so R (1) = 4, which consists of 1 = 1 ^ 2 + 0 ^ 2, 1 = (-1) ^ 2 + 0 ^ 2, 1 = 0 ^ 2 + 1 ^ 2, 1 = 0 ^ 2 + (-1) ^ 2. given N, you are to calculate R (N ). inputNo more than 100 test cases. each case contains only one integer N (N <= 10 ^ 9 ). outputFor each N, print R (N) in one line. sample Input26102565 Sample Output4081216HintFor the fourth test case, (A, B) can be (), (0,-5), (5, 0), (-5, 0), (3, 4 ), (3,-4), (-), (-3,-4), (), (4,-3), (-), (-4, -3) Source2011 Multi-Uni Versity Training Contest 1-Host by HNU the question is very easy to understand, find how many groups a, B can meet a ^ 2 + B ^ 2 = n. n is a maximum of 10 ^ 9, and it is certainly not allowed to enumerate brute force. Then enumerate a> B> = 0. Then, in each case, x 4 is used. A, B; a,-B;-a, B;-a,-B; if B = 0, 5, 0;-5, 0,-5, 5; also, see the code for details. Address: R (N) AC code:
# Include <iostream> # include <cstring> # include <string> # include <cstdio> # include <cmath> using namespace std; int main () {int n, I, a, B, ma, res; while (~ Scanf ("% d", & n) {ma = sqrt (double (n); // The largest a, a> B> = 0 res = 0; for (a = 1; a <= ma; a ++) {B = sqrt (double (n-a * )); if (a * a + B * B = n) res + = 4; // a, B; a,-B;-a, B;-, -B;} cout <res <endl;} return 0;} // 46 MS 280 K