QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#823831#8428. Partition into TeamsInvincibleAC ✓14ms15812kbC++231.8kb2024-12-21 10:07:442024-12-21 10:07:45

Judging History

你现在查看的是最新测评结果

  • [2024-12-21 10:07:45]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:15812kb
  • [2024-12-21 10:07:44]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
using namespace __gnu_pbds;
bool Mbe;

//char buf[1<<20],*p1,*p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
int read() {
	int s = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return f ? s : -s;
}
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(x>y)x=y;}

const int N=1000005;
int n,p,fac[N],ifac[N],ans;
int fpow(int x,int k=p-2){
	int res=1;
	for(;k;k>>=1){
		if(k&1)res=res*x%p;
		x=x*x%p;
	}
	return res;
}
int C(int x,int y){return x<y?0:fac[x]*ifac[y]%p*ifac[x-y]%p;}

bool Med;
signed main() {
	fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
	n=read(),p=read();
	fac[0]=1;
	rep(i,1,p-1)fac[i]=fac[i-1]*i%p;
	ifac[p-1]=fpow(fac[p-1]);
	per(i,p-1,1)ifac[i-1]=ifac[i]*i%p;
	ans=1;
	int now=n;
	while(now){
		int x=now%p,sum=0;
		rep(i,0,x-i)sum=(sum+C(x,i)*C(x-i,i))%p;
		ans=ans*sum%p;
		now/=p;
	}
	ans=(fpow(3,n)-ans+p)*fpow(2)%p;
	printf("%lld\n",ans);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5876kb

input:

5 5

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

5 7

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5976kb

input:

789 97

output:

53

result:

ok 1 number(s): "53"

Test #4:

score: 0
Accepted
time: 1ms
memory: 6000kb

input:

98 23

output:

10

result:

ok 1 number(s): "10"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5912kb

input:

398 7

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5916kb

input:

272 31

output:

18

result:

ok 1 number(s): "18"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5940kb

input:

920 199

output:

39

result:

ok 1 number(s): "39"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5908kb

input:

390 5167

output:

1236

result:

ok 1 number(s): "1236"

Test #9:

score: 0
Accepted
time: 1ms
memory: 6192kb

input:

445 24337

output:

4546

result:

ok 1 number(s): "4546"

Test #10:

score: 0
Accepted
time: 10ms
memory: 15812kb

input:

28 586501

output:

269032

result:

ok 1 number(s): "269032"

Test #11:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

304 5

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 1ms
memory: 5864kb

input:

7158 41

output:

16

result:

ok 1 number(s): "16"

Test #13:

score: 0
Accepted
time: 1ms
memory: 5876kb

input:

8487 331

output:

148

result:

ok 1 number(s): "148"

Test #14:

score: 0
Accepted
time: 1ms
memory: 7984kb

input:

501 6763

output:

363

result:

ok 1 number(s): "363"

Test #15:

score: 0
Accepted
time: 1ms
memory: 6476kb

input:

3011 61129

output:

49319

result:

ok 1 number(s): "49319"

Test #16:

score: 0
Accepted
time: 6ms
memory: 10868kb

input:

7266 358159

output:

7643

result:

ok 1 number(s): "7643"

Test #17:

score: 0
Accepted
time: 1ms
memory: 5856kb

input:

360860 7

output:

1

result:

ok 1 number(s): "1"

Test #18:

score: 0
Accepted
time: 1ms
memory: 5800kb

input:

154939 19

output:

8

result:

ok 1 number(s): "8"

Test #19:

score: 0
Accepted
time: 1ms
memory: 5932kb

input:

813268 47

output:

40

result:

ok 1 number(s): "40"

Test #20:

score: 0
Accepted
time: 1ms
memory: 5932kb

input:

965601 1531

output:

1147

result:

ok 1 number(s): "1147"

Test #21:

score: 0
Accepted
time: 3ms
memory: 8332kb

input:

689332 78079

output:

17208

result:

ok 1 number(s): "17208"

Test #22:

score: 0
Accepted
time: 1ms
memory: 8032kb

input:

287719 34369

output:

15373

result:

ok 1 number(s): "15373"

Test #23:

score: 0
Accepted
time: 0ms
memory: 5864kb

input:

439237583 7

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 1ms
memory: 5852kb

input:

319142531 79

output:

21

result:

ok 1 number(s): "21"

Test #25:

score: 0
Accepted
time: 1ms
memory: 5940kb

input:

592330255 631

output:

530

result:

ok 1 number(s): "530"

Test #26:

score: 0
Accepted
time: 1ms
memory: 5816kb

input:

164278463 4517

output:

3038

result:

ok 1 number(s): "3038"

Test #27:

score: 0
Accepted
time: 0ms
memory: 8556kb

input:

753671285 65371

output:

22369

result:

ok 1 number(s): "22369"

Test #28:

score: 0
Accepted
time: 14ms
memory: 15348kb

input:

289665297 663127

output:

168503

result:

ok 1 number(s): "168503"

Test #29:

score: 0
Accepted
time: 1ms
memory: 5976kb

input:

350585676619 7

output:

5

result:

ok 1 number(s): "5"

Test #30:

score: 0
Accepted
time: 1ms
memory: 5936kb

input:

4283693890775 31

output:

1

result:

ok 1 number(s): "1"

Test #31:

score: 0
Accepted
time: 0ms
memory: 6004kb

input:

1234727503131 151

output:

67

result:

ok 1 number(s): "67"

Test #32:

score: 0
Accepted
time: 0ms
memory: 5932kb

input:

9399186742989 1327

output:

678

result:

ok 1 number(s): "678"

Test #33:

score: 0
Accepted
time: 1ms
memory: 6044kb

input:

1409645481800 8719

output:

1939

result:

ok 1 number(s): "1939"

Test #34:

score: 0
Accepted
time: 11ms
memory: 15284kb

input:

3782178721166 552859

output:

458256

result:

ok 1 number(s): "458256"

Test #35:

score: 0
Accepted
time: 1ms
memory: 5884kb

input:

827235816874722972 5

output:

2

result:

ok 1 number(s): "2"

Test #36:

score: 0
Accepted
time: 1ms
memory: 5920kb

input:

648249960855836992 61

output:

56

result:

ok 1 number(s): "56"

Test #37:

score: 0
Accepted
time: 1ms
memory: 6008kb

input:

467138518199434341 563

output:

202

result:

ok 1 number(s): "202"

Test #38:

score: 0
Accepted
time: 1ms
memory: 5784kb

input:

616207494477524619 653

output:

95

result:

ok 1 number(s): "95"

Test #39:

score: 0
Accepted
time: 1ms
memory: 6208kb

input:

129689263663821851 34403

output:

30422

result:

ok 1 number(s): "30422"

Test #40:

score: 0
Accepted
time: 7ms
memory: 14972kb

input:

605206340470214709 479971

output:

381982

result:

ok 1 number(s): "381982"