QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#121148 | #3278. 算术 | zhouhuanyi | 5 | 1ms | 3568kb | C++11 | 1.3kb | 2023-07-07 17:10:03 | 2023-07-07 17:10:04 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 30
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int T,length;
long long tong[N+1],b,p,phip;
long long fast_pow(long long a,long long b)
{
long long res=1,mul=a;
while (b)
{
if (b&1) res=(__int128)(res)*mul%p;
mul=(__int128)(mul)*mul%p,b>>=1;
}
return res;
}
long long gcd(long long a,long long b)
{
if (!b) return a;
return gcd(b,a%b);
}
int main()
{
long long x;
T=read(),x=p=phip=read();
for (long long i=2;i*i<=p;++i)
if (x%i==0)
{
phip=phip/i*(i-1);
while (x%i==0) x/=i;
}
if (x!=1) phip=phip/x*(x-1);
x=phip;
for (long long i=2;i*i<=phip;++i)
if (x%i==0)
{
tong[++length]=i;
while (x%i==0) x/=i;
}
if (x!=1) tong[++length]=x;
while (T--)
{
b=read();
if (gcd(p,b)!=1)
{
puts("-1");
continue;
}
if (p==2)
{
puts("1");
continue;
}
x=phip;
for (int i=1;i<=length;++i)
while (x%tong[i]==0&&fast_pow(b,x/tong[i])==1)
x/=tong[i];
if (x&1) puts("-1");
else
{
if (x!=2) printf("%lld\n",(x-2)>>1);
else puts("2");
}
}
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3376kb
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: 1ms
memory: 3380kb
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: 0
Accepted
time: 0ms
memory: 3376kb
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:
ok 10 numbers
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #4:
score: 5
Accepted
time: 1ms
memory: 3440kb
input:
10 4 10 10 39 26 20 30 23 13 17 27
output:
-1 -1 2 -1 -1 -1 2 -1 -1 2
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
10 5 13 45 45 36 46 30 47 6 15 16
output:
1 -1 -1 -1 -1 -1 1 -1 -1 -1
result:
ok 10 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
10 6 8 31 37 22 29 7 44 12 29 32
output:
-1 -1 -1 -1 2 -1 -1 -1 2 -1
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
10 7 27 34 12 18 36 57 21 61 27 25
output:
2 2 2 -1 -1 -1 -1 2 2 -1
result:
ok 10 numbers
Test #8:
score: -5
Wrong Answer
time: 1ms
memory: 3444kb
input:
10 8 36 58 52 78 43 42 51 40 18 27
output:
-1 -1 -1 -1 2 -1 2 -1 -1 2
result:
wrong answer 5th numbers differ - expected: '-1', found: '2'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #10:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%