簡述:給定N,求 x1 + x2 + x3 + x4 + x5 = N的所有非負整數解的平方和。 思路:先求 x1 的所有解的平方和。當 x1 = k,x2 + x3 + x4 + x5 = N - k的非負整數解個數為C(N-k-1,3),産生了 k*k*C(N-k-1,3) 這麼多值。當 k 取遍 1,2...N-4 時,x1 這個位置上的解就求完了。然後根據輪轉對稱性,x2 , x3 , x4 , x5 都應該産生了這麼多值。 貼在這裡不是因為難,是自認為思路不錯。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include <cmath>
#define LL long long
#define eps (1e-8)
#define clr(A) memset(A,0,sizeof(A))
using namespace std;
int const mod = 7477777;
int const maxn = 100005;
int f[maxn],c[maxn];
int main()
{
int T,cnt = 0;
for(int i = 1;i<maxn;i++)
{
f[i] = ((LL)i*i) % mod;
c[i] = (LL)i*(i-1)*(i-2)/6 % mod;
}
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
if(n<5) {printf("Case %d: 0\n",++cnt);continue;}
int ret = 0;
for(int i = 1; i <= n-4; i++)
{
ret = ((LL)f[i]*c[n-i-1]+ret) % mod;
}
printf("Case %d: %d\n",++cnt,ret*5 % mod);
}
return 0;
}