Equation
x
For a certain n
For the answer may be very large, you are expected output the result after it modular m
In the next T
[Technical Specification]
1≤T<20
1≤n≤50000
1≤m≤1000000000
See the samples for more details.
2 3 100 5 100
Case #1: 2 Case #2: 3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
using namespace std;
int dp[500][50050]={0};
int main()
{
int t;scanf("%d",&t);
int v=1;
while(t--)
{
LL n,mod;
scanf("%lld%lld",&n,&mod);
int k=1;
while(k*(k+1)<=2*n)k++;
k--;
for(int i=0;i<=n;i++)dp[0][i]=0;
for(int i=0;i<=k;i++)dp[i][0]=0;
dp[0][0]=1;
for(int i=1;i<=k;i++)
for(int j=i;j<=n;j++)
dp[i][j]=(dp[i][j-i]+dp[i-1][j-i])%mod;
LL ans=0;
for(int i=1;i<=k;i++)
ans+=dp[i][n],ans%=mod;
printf("Case #%d: %lld\n",v++,ans);
}
}
6160



被折叠的 条评论
为什么被折叠?



