QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#79597#3278. 算术tricyzhkx5 2ms3644kbC++141.0kb2023-02-20 15:23:162023-02-20 15:23:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-20 15:23:20]
  • 评测
  • 测评结果:5
  • 用时:2ms
  • 内存:3644kb
  • [2023-02-20 15:23:16]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
ll Phi(ll n)
{
	ll ans=n;
	for(ll i=2;i*i<=n;i++)
		if(n%i==0)
		{
			ans=ans/i*(i-1);
			for(;n%i==0;n/=i);
		}
	if(n>1) ans=ans/n*(n-1);
	return ans;
}
ll power(ll a,ll b,ll p)
{
	ll ans=1;
	for(;b;b>>=1,a=(lll)a*a%p)
		if(b&1) ans=(lll)ans*a%p;
	return ans;
}
int tot;
ll p,phi,pr[60],cnt[60];
ll Ord(ll n)
{
	ll ans=1;
	for(int i=1;i<=tot;i++)
	{
		ll cur=phi;
		for(int j=0;j<cnt[i];j++) cur/=pr[i];
		ll pw=power(n,cur,p);
		for(;pw>1;pw=power(pw,pr[i],p)) ans*=pr[i];
	}
	return ans;
}
int main()
{
	int T;
	cin>>T>>p;
	ll t=phi=Phi(p);
	for(ll i=2;i*i<=t;i++)
		if(t%i==0)
		{
			pr[++tot]=i;
			for(;t%i==0;t/=i) cnt[tot]++;
		}
	if(t>1) pr[++tot]=t,cnt[tot]=1;
	while(T--)
	{
		ll b;
		scanf("%lld",&b);
		if(__gcd(p,b)>1){puts("-1");continue;}
		if(p==2){puts("1");continue;}
		ll ord=Ord(b),ans;
		if(ord&1){puts("-1");continue;}
		ans=ord/2;
		if(ans<=1) ans+=ord;
		printf("%lld\n",ans-1);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 2ms
memory: 3568kb

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: 2ms
memory: 3504kb

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: 2ms
memory: 3504kb

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: 0ms
memory: 3644kb

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: 0ms
memory: 3520kb

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: 3616kb

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: 2ms
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: 3520kb

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%