打表解之

View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 const int N=(1<<15)+1;
 7 int po[200],ans[N+2];
 8 int main()
 9 {
10     for(int i=1;i<200;po[i]=i*i,i++);
11     memset(ans,0,sizeof(ans));
12     for(int i1=1,tp1;po[i1]<=N;i1++)
13     {
14         ans[tp1=po[i1]]++;
15         for(int i2=i1,tp2;tp1+po[i2]<=N;i2++)
16         {
17             ans[tp2=tp1+po[i2]]++;
18             for(int i3=i2,tp3;tp2+po[i3]<=N;i3++)
19             {
20                 ans[tp3=tp2+po[i3]]++;
21                 for(int i4=i3;tp3+po[i4]<=N;i4++)
22                     ans[tp3+po[i4]]++;
23             }
24         }
25     }
26     int n;
27     while(scanf("%d",&n)&&n)
28         printf("%d\n",ans[n]);
29     return 0;
30 }