四 定理是众所周知的:任意一个正整数n,可以分解为不超过四个
数的平 和。例如:25=1 22+2 +4 ,当然还有其他的分
方案,25=4 +32和25=5 。给定的正整数n,编程统计它能
解的 案总数。注意:25=4 3 和25=32+4 视为一种方
输入格式
第一行为正整数T(T 100),表示数组的组数。
接下来T行,每行一个正整数n(n 40000)。
输出格式
T行,每行一个整数表示对应的方案数。
格式说明
输出时每行未尾的多余空格,不影响答宰正确性
样例输入
2
5
12345
输出
3
432
代码:
#include<iostream>
#include<cmath>
using namespace std;
int judge(int num) {
int number = 0;
for (int a = 1; a * a <= num; a++) {
if (a * a == num) {
number++;
break;
}
for (int b = a; b * b + a * a <= num; b++) {
if (b * b + a * a == num) {
number++;
break;
}
for (int c = b; c * c + b * b + a * a <= num; c++) {
if (c * c + b * b + a * a == num) {
number++;
break;
}
for (int d = c; d * d + c * c + b * b + a * a <= num; d++) {
if (d * d + c * c + b * b + a * a == num) {
number++;
break;
}
}
}
}
}
return number;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
int res = judge(num);
cout << res << endl;
}
return 0;
}