QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67662#5099. 朝圣道wzh20210 1451ms9212kbC++141.9kb2022-12-10 22:00:242022-12-10 22:00:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 22:00:25]
  • 评测
  • 测评结果:0
  • 用时:1451ms
  • 内存:9212kb
  • [2022-12-10 22:00:24]
  • 提交

answer

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _1 first
#define _2 second
const int N = 1000010, L = 50;
int p, phi;
int cnt;
pair <int, int> vec[L];
int fac[L][N];
int exgcd(int a, int b, int & x, int & y) {
	if (!b) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int inv(int a, int b) {
	int x, y, d = exgcd(a, b, x, y);
	int t = b / d;
	x = (x % t + t) % t;
	return x;
}
int quick_pow(int x, int y, int p) {
	int res = 1;
	for (; y; y >>= 1, x = (ll) x * x % p)
		if (y & 1) res = (ll) res * x % p;
	return res;
}
int calc(ll n, int k) {
	int x = vec[k]._1;
	int p = vec[k]._2;
	int phi = p / x * (x - 1);
	return n ? (ll) quick_pow(fac[k][p], n / p % phi + phi, p) * fac[k][n % p] % p * calc(n / x, k) % p : 1;
}
int solve(ll n, int k) {
	ll cnt = 0;
	int x = vec[k]._1;
	int p = vec[k]._2;
	int phi = p / x * (x - 1);
	for (ll i = n << 1; i; i /= x) cnt += i / x;
	for (ll i = n; i; i /= x) cnt -= i / x * 2;
	int t = calc(n, k);
	return (ll) quick_pow(x, cnt % phi + phi, p) * calc(n << 1, k) % p * inv((ll) t * t % p, p) % p;
}
void init(int o, int p0) {
	p = p0;
	phi = p;
	cnt = 0;
	for (int i = 2; i * i <= p0; ++i) {
		if (p0 % i) continue;
		int d = 1;
		while (!(p0 % i)) {
			p0 /= i;
			d *= i;
		}
		vec[cnt++] = {i, d};
		phi = phi / i * (i - 1);
	}
	if (p0 > 1) {
		vec[cnt++] = {p0, p0};
		phi = phi / p0 * (p0 - 1);
	}
	for (int i = 0; i < cnt; ++i) {
		fac[i][0] = 1;
		for (int j = 1; j <= vec[i]._2; ++j)
			fac[i][j] = (ll) fac[i][j - 1] * (j % vec[i]._1 ? j : 1) % vec[i]._2;
	}
}
int Lucas(ll n) {
	int res = 0;
	for (int i = 0; i < cnt; ++i)
		res = (res + (ll) solve(n, i) * (p / vec[i]._2) % p * inv(p / vec[i]._2 % vec[i]._2, vec[i]._2) % p) % p;
	return res;
}
int ask(ll n) {
	return (ll) inv(quick_pow(4, n % phi + phi, p), p) * (n % p) % p * Lucas(n) % p;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1451ms
memory: 9212kb

input:

1 910276 554767
6
10
7
4
10
12
9
3
3
5
7
10
5
6
1
6
3
9
6
8
12
11
8
2
12
5
9
3
8
2
12
11
2
3
4
9
2
5
5
11
6
4
8
11
3
9
2
2
8
9
2
8
9
6
2
9
2
10
10
7
5
6
4
4
11
12
8
8
2
2
4
3
3
5
6
6
8
11
6
9
9
3
4
1
2
2
6
9
9
2
3
2
12
6
1
7
2
4
12
11
4
7
6
3
9
4
6
5
3
3
12
6
2
1
1
7
2
6
5
9
11
6
3
4
11
1
2
4
5
4
10...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st numbers differ - expected: '5419', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 7ms
memory: 4776kb

input:

3 1 334547
8234

output:

0

result:

wrong answer 1st numbers differ - expected: '179079', found: '0'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

6 958477 522361
280121915553826833
734266539148641647
72849162479700582
274266741463686096
60278972064195458
828423669427600612
571432949203039978
518511460268700898
486268614705621285
19216283231217074
611458416727512530
175147354285288662
799769622289998997
400123443628688299
145546980862133838
40...

output:

Unauthorized output

result:


Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 36ms
memory: 3668kb

input:

8 9963 251
831797004675585320
494759973681332858
701341496127272302
252910460485222469
250965009655458584
366193481309061299
633134388675839346
791999098066205672
196620805863610860
363773642045280947
466508590762410710
407790578717064135
181590911404670570
570642047249889864
70138464625729452
23634...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 25th numbers differ - expected: '204', found: '0'

Subtask #9:

score: 0
Skipped

Dependency #2:

0%