Luogp1586 Sifang theorem and P1586 Sifang Theorem
Description
The square theorem is well known: any positive integer nn can be decomposed into a sum of squares of up to four integers. Example: 25 = 1 ^ {2} + 2 ^ {2} + 2 ^ {2} + 4 ^ {2} 25 = 12 + 22 + 22 + 42, of course there are other decomposition solutions, 25 = 4 ^ {2} + 3 ^ {2} 25 = 42 + 32 and 25 = 5 ^ {2} 25 = 52. The total number of solutions that can be decomposed by the given positive integer nn. Note: 25 = 4 ^ {2} + 3 ^ {2} 25 = 42 + 32 and 25 = 3 ^ {2} + 4 ^ {2} 25 = 32 + 42 solution.
Input/Output Format
Input Format:
The first behavior is a positive integer tt (t \ le 100t ≤ 100), and the next tt row contains a positive integer nn (n \ le 32768n ≤ 32768 ).
Output Format:
For each positive integer nn, the total number of output solutions.
Input and Output sample input sample #1: Copy
12003
Output sample #1: Copy 48
$ N ^ 4 $ the positive solution of brute force is a backpack $ dp [I] [j] $, which indicates the number of solutions $ j $
// luogu-judger-enable-o2#include<iostream>#include<cstdio>#define LL long long using namespace std;const int MAXN=1e5+10;int dp[5][MAXN];int main(){ #ifdef WIN32 freopen("a.in","r",stdin); #else #endif dp[0][0]=1; for(register int i=1;i<=200;i++) for(register int j=1;j<=4;j++) for(register int k=1;k<=32768;k++) if(i*i<=k) dp[j][k]+=dp[j-1][k-i*i]; int T; scanf("%d",&T); while(T--) { int a; scanf("%d",&a); printf("%d\n",dp[1][a]+dp[2][a]+dp[3][a]+dp[4][a]); } return 0;}
// luogu-judger-enable-o2#include<iostream>#include<cstdio>#define LL long long using namespace std;const int MAXN=1e6+10;int mul[MAXN],dp[MAXN];int ans[MAXN];int main(){ #ifdef WIN32 freopen("a.in","r",stdin); #else #endif int N=200; for(int i=1;i<=N;i++) mul[i]=i*i; for(int i=1;i<=N;i++) ans[ mul[i] ] ++; for(int i=1;i<=N;i++) for(int j=i;j<=N;j++) ans[ mul[i]+mul[j] ] ++; for(int i=1;i<=N;i++) for(int j=i;j<=N;j++) for(int k=j;k<=N;k++) ans[ mul[i]+mul[j]+mul[k] ] ++; for(int i=1;i<=N;i++) for(int j=i;j<=N;j++) for(int k=j;k<=N;k++) for(int l=k;l<=N;l++) ans[ mul[i]+mul[j]+mul[k]+mul[l] ]++; int T; scanf("%d",&T); while(T--) { int a; scanf("%d",&a); printf("%d\n",ans[a]); } return 0;}