QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19924#2601. Lucky Ticketslinmuhan#AC ✓762ms34804kbC++14757b2022-02-13 20:47:542022-05-08 01:35:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 01:35:51]
  • 评测
  • 测评结果:AC
  • 用时:762ms
  • 内存:34804kb
  • [2022-02-13 20:47:54]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2000010;
ll n, s, q, Ans;
ll fac[N], ifac[N];
ll qpow(ll a,ll b,ll t){ll ans;for(ans=1;b;b>>=1,ans%=t,a%=t)ans*=(b&1?a:1),a=a*a;return ans;}
int main () {
	cin >> n >> s >> q;
	fac[0] = 1ll; for (int i=1;i<=n+q;i++) fac[i] = fac[i - 1] * i % q;
	ifac[n + q] = qpow (fac[n + q], q - 2, q);
	for (int i=n+q;i>=0;i--) ifac[i] = ifac[i + 1] * (i + 1) % q;
	ll TMP = 0;
	for (int i=0;i<q;i++) TMP += qpow (2, i, q), TMP %= q;
	for (int i=0;i<n;i++) {
		ll prd = qpow (i, q, n);
		ll sum = q * i % n;
		ll pd = (prd + sum) % n;
		if (pd == s) {
			Ans += fac[i + q] * ifac[i] % q;
			Ans %= q; Ans += TMP * i % q;
			Ans %= q;
		}
	}
	cout << Ans << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 5768kb

input:

2 0 2

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

10 9 2

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

3 2 3

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

2 1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4 0 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

4 2 3

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

20 4 19

output:

5

result:

ok 1 number(s): "5"

Test #8:

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

input:

30 2 37

output:

23

result:

ok 1 number(s): "23"

Test #9:

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

input:

87 22 67

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

829 135 857

output:

803

result:

ok 1 number(s): "803"

Test #11:

score: 0
Accepted
time: 8ms
memory: 5764kb

input:

6120 2790 9851

output:

4622

result:

ok 1 number(s): "4622"

Test #12:

score: 0
Accepted
time: 39ms
memory: 8660kb

input:

77263 13087 50147

output:

26904

result:

ok 1 number(s): "26904"

Test #13:

score: 0
Accepted
time: 495ms
memory: 25500kb

input:

682298 437284 638801

output:

10038

result:

ok 1 number(s): "10038"

Test #14:

score: 0
Accepted
time: 523ms
memory: 26296kb

input:

823965 703789 575623

output:

483248

result:

ok 1 number(s): "483248"

Test #15:

score: 0
Accepted
time: 748ms
memory: 34700kb

input:

1000000 394496 999983

output:

755554

result:

ok 1 number(s): "755554"

Test #16:

score: 0
Accepted
time: 751ms
memory: 34784kb

input:

1000000 24900 999451

output:

996185

result:

ok 1 number(s): "996185"

Test #17:

score: 0
Accepted
time: 748ms
memory: 34764kb

input:

999750 14190 999671

output:

191073

result:

ok 1 number(s): "191073"

Test #18:

score: 0
Accepted
time: 721ms
memory: 34384kb

input:

946312 10286 997741

output:

744939

result:

ok 1 number(s): "744939"

Test #19:

score: 0
Accepted
time: 762ms
memory: 34804kb

input:

997742 0 997741

output:

565729

result:

ok 1 number(s): "565729"

Test #20:

score: 0
Accepted
time: 755ms
memory: 34468kb

input:

977762 0 977761

output:

0

result:

ok 1 number(s): "0"