QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#267342 | #3278. 算术 | djwj233 | 0 | 0ms | 3864kb | C++14 | 1.5kb | 2023-11-27 10:08:51 | 2023-11-27 10:08:52 |
answer
#include<bits/stdc++.h>
using namespace std;
#define fo(v,a,b) for(int v = a; v <= b; v++)
#define fr(v,a,b) for(int v = a; v >= b; v--)
#define cl(a,v) memset(a, v, sizeof(a))
typedef long long ll;
ll mul(ll A, ll B, ll P){
ll C = A * B - (ll)((double)A * B / P + 0.1) * P;
return C < 0 ? C + P : C;
}
ll power(ll a, ll x, ll P) {
ll res = 1;
while(x) {
if(x & 1LL) res = mul(res, a, P);
a = mul(a, a, P), x >>= 1;
} return res;
}
const int N = 110;
ll pr[N]; int q[N], cc;
void Divide(ll P) {
cc = 0, cl(pr, 0), cl(q, 0);
for(int i = 2; (ll)i * i <= P; i++)
if(P % i == 0) {
cc++, pr[cc] = i;
while(P % i == 0) P /= i, q[cc]++;
}
if(P > 1) pr[++cc] = P, q[cc] = 1;
}
ll b, P, phiP, ans;
void Main() {
scanf("%lld", &b), b %= P;
if(__gcd(b, P) != 1) return puts("-1"), void();
ans = phiP;
fo(i, 1, cc) {
while(ans % pr[i] == 0) {
if(power(b, ans / pr[i], P) == 1)
ans /= pr[i];
else break;
}
}
if(ans & 1) return puts("-1"), void();
ll d = ans / 2;
if(power(b, d, P) != P - 1) return puts("-1"), void();
ll res = d - 1; if(res == 0) res += ans;
printf("%lld\n", res);
}
int main()
{
int T; scanf("%d%lld", &T, &P);
Divide(P), phiP = 1;
fo(i, 1, cc) {
phiP *= pr[i] - 1;
fo(j, 2, q[i]) phiP *= pr[i];
}
Divide(phiP);
while(T--) Main();
return 0;
}
/*
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 3864kb
input:
10 3 10 7 13 4 17 28 29 13 4 30
output:
-1 -1 -1 -1 2 -1 2 -1 -1 -1
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
10 3 17 21 29 8 25 21 8 14 26 7
output:
2 -1 2 2 -1 -1 2 2 2 -1
result:
ok 10 numbers
Test #3:
score: -5
Wrong Answer
time: 0ms
memory: 3816kb
input:
10 2 14 12 20 12 7 4 6 12 16 13
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 5th numbers differ - expected: '1', found: '-1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%
Subtask #10:
score: 0
Skipped
Dependency #1:
0%