QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#828003 | #8428. Partition into Teams | hxhhxh | TL | 43ms | 14864kb | C++20 | 650b | 2024-12-23 12:17:54 | 2024-12-23 12:17:55 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int p,m,F[5000006],Inv[5000006];
int pw(int x,int y){
int res=1;
for(;y;y>>=1,x=x*x%p) if(y&1) res=res*x%p;
return res;
}
int clc(int x,int y){
if(x<y||y<0) return 0;
return F[x]*Inv[y]%p*Inv[x-y]%p;
}
int C(int x,int y){
if(y==0) return 1;
return C(x/p,y/p)*clc(x%p,y%p)%p;
}
int slv(int n){
int res=0;
for(int i=0;i<=n/2;i++) res=(res+C(i*2,i)*C(n,i*2))%p;
return res;
}
signed main(){
cin>>m>>p;
for(int i=F[0]=1;i<p;i++) F[i]=F[i-1]*i%p;
Inv[p-1]=p-1;
for(int i=p-1;i;i--) Inv[i-1]=Inv[i]*i%p;
cout<<((pw(3,m)-slv(m))*((-p)/2)%p+p)%p;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5648kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
789 97
output:
53
result:
ok 1 number(s): "53"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5520kb
input:
98 23
output:
10
result:
ok 1 number(s): "10"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5520kb
input:
398 7
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
272 31
output:
18
result:
ok 1 number(s): "18"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
920 199
output:
39
result:
ok 1 number(s): "39"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
390 5167
output:
1236
result:
ok 1 number(s): "1236"
Test #9:
score: 0
Accepted
time: 0ms
memory: 5768kb
input:
445 24337
output:
4546
result:
ok 1 number(s): "4546"
Test #10:
score: 0
Accepted
time: 10ms
memory: 14864kb
input:
28 586501
output:
269032
result:
ok 1 number(s): "269032"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5720kb
input:
304 5
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5640kb
input:
7158 41
output:
16
result:
ok 1 number(s): "16"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
8487 331
output:
148
result:
ok 1 number(s): "148"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5692kb
input:
501 6763
output:
363
result:
ok 1 number(s): "363"
Test #15:
score: 0
Accepted
time: 0ms
memory: 7572kb
input:
3011 61129
output:
49319
result:
ok 1 number(s): "49319"
Test #16:
score: 0
Accepted
time: 6ms
memory: 10976kb
input:
7266 358159
output:
7643
result:
ok 1 number(s): "7643"
Test #17:
score: 0
Accepted
time: 32ms
memory: 5648kb
input:
360860 7
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 9ms
memory: 5644kb
input:
154939 19
output:
8
result:
ok 1 number(s): "8"
Test #19:
score: 0
Accepted
time: 43ms
memory: 5700kb
input:
813268 47
output:
40
result:
ok 1 number(s): "40"
Test #20:
score: 0
Accepted
time: 26ms
memory: 5572kb
input:
965601 1531
output:
1147
result:
ok 1 number(s): "1147"
Test #21:
score: 0
Accepted
time: 22ms
memory: 10076kb
input:
689332 78079
output:
17208
result:
ok 1 number(s): "17208"
Test #22:
score: 0
Accepted
time: 8ms
memory: 5916kb
input:
287719 34369
output:
15373
result:
ok 1 number(s): "15373"
Test #23:
score: -100
Time Limit Exceeded
input:
439237583 7