QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327031 | #8015. 鸡 | zjy0001 | 100 ✓ | 0ms | 3868kb | C++14 | 1.1kb | 2024-02-14 18:07:26 | 2024-02-14 18:07:26 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
int P;
inline int qpow(int x,int y){
int z=1;
for(;y;(y>>=1)&&(x=x*1ll*x%P))
if(y&1)z=z*1ll*x%P;
return z;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
#define LOCAL
#ifndef LOCAL
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
int n,m;
cin>>n>>m>>P;
vector<int>f(max(n+1,8));
const int inv3=qpow(3,P-2);
const int inv6=qpow(6,P-2);
const int inv12=qpow(12,P-2);
f[2]=(m+1ll)*(m+1)%P;
f[3]=(((m+6ll)*m+8)%P*m%P*inv3+1)%P;
f[4]=(((m*7ll+15)*m+11)%P*m%P*inv3+1)%P;
f[5]=((((m*7ll+68)*m+89)%P*m+52)%P*m%P*inv12%P+1)%P;
f[6]=((((m*25ll+76)%P*m+71)%P*m+32)%P*m%P*inv6+1)%P;
f[7]=(((((m*5ll+74)*m+133)%P*m+94)%P*m+36)%P*m%P*inv6+1)%P;
for(int i=8;i<=n;++i)f[i]=((f[i-1]-f[i-3])*2ll+f[i-4]+(((LL)f[i-2]-f[i-3]-f[i-4]+f[i-5])*2+1ll*m*(f[i-6]-f[i-4]))%P*m)%P;
cout<<(f[n]<0?f[n]+P:f[n]);
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 3816kb
input:
5 5 1004326439
output:
1281
result:
ok 1 number(s): "1281"
Test #2:
score: 5
Accepted
time: 0ms
memory: 3548kb
input:
5 4 1002682123
output:
649
result:
ok 1 number(s): "649"
Test #3:
score: 5
Accepted
time: 0ms
memory: 3816kb
input:
287 1 1003060133
output:
328406329
result:
ok 1 number(s): "328406329"
Test #4:
score: 5
Accepted
time: 0ms
memory: 3584kb
input:
279 1 1004432189
output:
222258837
result:
ok 1 number(s): "222258837"
Test #5:
score: 5
Accepted
time: 0ms
memory: 3500kb
input:
300 1 1005912203
output:
707086810
result:
ok 1 number(s): "707086810"
Test #6:
score: 5
Accepted
time: 0ms
memory: 3548kb
input:
288 5 1003307827
output:
964512417
result:
ok 1 number(s): "964512417"
Test #7:
score: 5
Accepted
time: 0ms
memory: 3860kb
input:
281 5 1008854383
output:
755282155
result:
ok 1 number(s): "755282155"
Test #8:
score: 5
Accepted
time: 0ms
memory: 3556kb
input:
270 5 1007619367
output:
431828317
result:
ok 1 number(s): "431828317"
Test #9:
score: 5
Accepted
time: 0ms
memory: 3616kb
input:
292 5 1002449813
output:
183613546
result:
ok 1 number(s): "183613546"
Test #10:
score: 5
Accepted
time: 0ms
memory: 3556kb
input:
300 5 1005897091
output:
915308166
result:
ok 1 number(s): "915308166"
Test #11:
score: 5
Accepted
time: 0ms
memory: 3556kb
input:
45 50 1009100993
output:
940158800
result:
ok 1 number(s): "940158800"
Test #12:
score: 5
Accepted
time: 0ms
memory: 3552kb
input:
49 50 1001428049
output:
1045902
result:
ok 1 number(s): "1045902"
Test #13:
score: 5
Accepted
time: 0ms
memory: 3552kb
input:
49 50 1007851073
output:
922264698
result:
ok 1 number(s): "922264698"
Test #14:
score: 5
Accepted
time: 0ms
memory: 3576kb
input:
50 50 1005625571
output:
442192770
result:
ok 1 number(s): "442192770"
Test #15:
score: 5
Accepted
time: 0ms
memory: 3624kb
input:
290 300 1005068699
output:
484359497
result:
ok 1 number(s): "484359497"
Test #16:
score: 5
Accepted
time: 0ms
memory: 3784kb
input:
270 300 1003440637
output:
899894137
result:
ok 1 number(s): "899894137"
Test #17:
score: 5
Accepted
time: 0ms
memory: 3560kb
input:
300 300 1008561979
output:
33407754
result:
ok 1 number(s): "33407754"
Test #18:
score: 5
Accepted
time: 0ms
memory: 3868kb
input:
2991 3000 1004658859
output:
167444547
result:
ok 1 number(s): "167444547"
Test #19:
score: 5
Accepted
time: 0ms
memory: 3788kb
input:
2870 3000 1004054173
output:
860666062
result:
ok 1 number(s): "860666062"
Test #20:
score: 5
Accepted
time: 0ms
memory: 3600kb
input:
3000 3000 1009539589
output:
696222334
result:
ok 1 number(s): "696222334"