Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- long long dp[1000007];
- void pre()
- {
- dp[1]=1;
- dp[2]=1;
- dp[3]=3;
- for(int i=4; i<=1000002; i++){
- dp[i] = i*dp[i-1] + i*dp[i-2] - dp[i-1] - 2*dp[i-2];
- dp[i] = dp[i] % 1000000007;
- }
- }
- int main()
- {
- //freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- pre();
- int css,cs;
- scanf("%d",&css);
- for(cs=1; cs<=css; cs++){
- int a;
- scanf("%d",&a);
- printf("Case %d: %lld\n",cs,dp[a]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment