QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#481776#144. Primitive root / 原根ucup-team10043 1ms4200kbC++172.0kb2024-07-17 14:07:272024-07-17 14:07:27

Judging History

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

  • [2024-07-17 14:07:27]
  • 评测
  • 测评结果:3
  • 用时:1ms
  • 内存:4200kb
  • [2024-07-17 14:07:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using LL=__int128;
vector<int>test={2,3,5,7,11,13,17,19,23,29,31,37};
ll mod;
ll qpow(LL x,ll y,ll mod,LL ans=1){
	for(;y;(x*=x)%=mod,y>>=1)if(y&1)(ans*=x)%=mod;
	return ans;
}
bool isprime(ll n){
	if(n<=2)return n==2;
	if(n%2==0)return 0;
	ll a=n-1;
	int k=0;
	for(;a%2==0;a/=2)k++;
	auto chk=[&](int p){
		p%=n;
		if(p==0)return 1;
		ll x=qpow(p,a,n);
		if(x==1)return 1;
		for(int i=0;i<k;i++){
			if(x==n-1)return 1;
			x=(LL)x*x%n;
		}
		return 0;
	};
	for(int x:test)if(!chk(x))return 0;
	return 1;
}
vector<ll>p;
mt19937_64 rnd(time(0));
ll find(ll n){
	ll x=rnd()%(n-2)+1;
	auto f=[&](ll a){
		return ((LL)a*a+x)%n;
	};
	ll a=rnd()%n,b=f(a);
	for(;a!=b;a=f(a),b=f(f(b))){
		ll x=__gcd(abs(a-b),n);
		if(x>1)return x;
	}
	return n;
}
void divide(ll n){
	if(isprime(n))return p.push_back(n);
	ll x;
	do x=find(n);while(x==n);
	divide(x),divide(n/x);
}
ll phi;
bool chk(ll x){
	if(__gcd(x,mod)>1)return 0;
	for(ll y:p){
		debug(x,phi/y,mod,qpow(x,phi/y,mod));
		if(qpow(x,phi/y,mod)==1)return 0;
	}
	return 1;
}
int main(){
	cin>>mod;
	if(mod==2)puts("1"),exit(0);
	if(mod==4)puts("3"),exit(0);
	divide(mod),sort(all(p));
	debug(p);
	if(p[0]==2){
		for(int i=1;i<p.size();i++){
			if(p[i]!=p[1])puts("-1"),exit(0);
		}
		p.erase(p.begin());
		ll x=p.back()-1;
		p.pop_back();
		divide(x);
	}else{
		for(ll x:p){
			if(x!=p.back())puts("-1"),exit(0);
		}
		ll x=p.back()-1;
		p.pop_back();
		divide(x);
	}
	debug(p);
	phi=1;
	for(ll x:p)phi*=x;
	sort(all(p)),p.erase(unique(all(p)),p.end());
	for(ll g=1;g<mod;g++){
		if(chk(g))printf("%lld\n",g),exit(0);
	}
	puts("-1");
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

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

input:

433

output:

5

result:

ok good solution

Test #2:

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

input:

197

output:

2

result:

ok good solution

Test #3:

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

input:

733

output:

6

result:

ok good solution

Test #4:

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

input:

859

output:

2

result:

ok good solution

Test #5:

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

input:

449

output:

3

result:

ok good solution

Test #6:

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

input:

263

output:

5

result:

ok good solution

Test #7:

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

input:

683

output:

5

result:

ok good solution

Test #8:

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

input:

17

output:

3

result:

ok good solution

Test #9:

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

input:

359

output:

7

result:

ok good solution

Test #10:

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

input:

89

output:

3

result:

ok good solution

Test #11:

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

input:

647

output:

5

result:

ok good solution

Test #12:

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

input:

487

output:

3

result:

ok good solution

Test #13:

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

input:

677

output:

2

result:

ok good solution

Test #14:

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

input:

829

output:

2

result:

ok good solution

Test #15:

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

input:

227

output:

2

result:

ok good solution

Test #16:

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

input:

151

output:

6

result:

ok good solution

Test #17:

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

input:

607

output:

3

result:

ok good solution

Test #18:

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

input:

661

output:

2

result:

ok good solution

Test #19:

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

input:

151

output:

6

result:

ok good solution

Test #20:

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

input:

101

output:

2

result:

ok good solution

Test #21:

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

input:

5

output:

2

result:

ok good solution

Test #22:

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

input:

877

output:

2

result:

ok good solution

Test #23:

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

input:

139

output:

2

result:

ok good solution

Test #24:

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

input:

389

output:

2

result:

ok good solution

Test #25:

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

input:

421

output:

2

result:

ok good solution

Test #26:

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

input:

709

output:

2

result:

ok good solution

Test #27:

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

input:

331

output:

3

result:

ok good solution

Test #28:

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

input:

269

output:

2

result:

ok good solution

Test #29:

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

input:

797

output:

2

result:

ok good solution

Test #30:

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

input:

997

output:

7

result:

ok good solution

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #31:

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

input:

841

output:

2

result:

ok good solution

Test #32:

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

input:

289

output:

3

result:

ok good solution

Test #33:

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

input:

729

output:

2

result:

ok good solution

Test #34:

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

input:

169

output:

2

result:

ok good solution

Test #35:

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

input:

961

output:

3

result:

ok good solution

Test #36:

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

input:

31

output:

3

result:

ok good solution

Test #37:

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

input:

243

output:

2

result:

ok good solution

Test #38:

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

input:

625

output:

2

result:

ok good solution

Test #39:

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

input:

121

output:

2

result:

ok good solution

Test #40:

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

input:

125

output:

2

result:

ok good solution

Test #41:

score: -1
Time Limit Exceeded

input:

512

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 1
Accepted

Dependency #1:

100%
Accepted

Test #91:

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

input:

182233

output:

5

result:

ok good solution

Test #92:

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

input:

28771

output:

2

result:

ok good solution

Test #93:

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

input:

579239

output:

11

result:

ok good solution

Test #94:

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

input:

724747

output:

7

result:

ok good solution

Test #95:

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

input:

143513

output:

3

result:

ok good solution

Test #96:

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

input:

695509

output:

2

result:

ok good solution

Test #97:

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

input:

999217

output:

5

result:

ok good solution

Test #98:

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

input:

888161

output:

3

result:

ok good solution

Test #99:

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

input:

234287

output:

5

result:

ok good solution

Test #100:

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

input:

746483

output:

2

result:

ok good solution

Test #101:

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

input:

985003

output:

3

result:

ok good solution

Test #102:

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

input:

786959

output:

17

result:

ok good solution

Test #103:

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

input:

1097

output:

3

result:

ok good solution

Test #104:

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

input:

105527

output:

5

result:

ok good solution

Test #105:

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

input:

812519

output:

7

result:

ok good solution

Test #106:

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

input:

161599

output:

6

result:

ok good solution

Test #107:

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

input:

645131

output:

2

result:

ok good solution

Test #108:

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

input:

63397

output:

2

result:

ok good solution

Test #109:

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

input:

244429

output:

6

result:

ok good solution

Test #110:

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

input:

911453

output:

2

result:

ok good solution

Test #111:

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

input:

340477

output:

2

result:

ok good solution

Test #112:

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

input:

28351

output:

6

result:

ok good solution

Test #113:

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

input:

414277

output:

2

result:

ok good solution

Test #114:

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

input:

411923

output:

2

result:

ok good solution

Test #115:

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

input:

986281

output:

19

result:

ok good solution

Test #116:

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

input:

882047

output:

5

result:

ok good solution

Test #117:

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

input:

323009

output:

3

result:

ok good solution

Test #118:

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

input:

577153

output:

5

result:

ok good solution

Test #119:

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

input:

42281

output:

11

result:

ok good solution

Test #120:

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

input:

601823

output:

5

result:

ok good solution

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 1
Accepted

Dependency #4:

100%
Accepted

Test #181:

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

input:

842797909

output:

2

result:

ok good solution

Test #182:

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

input:

662460749

output:

2

result:

ok good solution

Test #183:

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

input:

583578713

output:

3

result:

ok good solution

Test #184:

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

input:

714745777

output:

19

result:

ok good solution

Test #185:

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

input:

626528689

output:

7

result:

ok good solution

Test #186:

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

input:

848747719

output:

3

result:

ok good solution

Test #187:

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

input:

780868019

output:

2

result:

ok good solution

Test #188:

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

input:

295695817

output:

5

result:

ok good solution

Test #189:

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

input:

950964661

output:

6

result:

ok good solution

Test #190:

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

input:

219526067

output:

2

result:

ok good solution

Test #191:

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

input:

763440683

output:

2

result:

ok good solution

Test #192:

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

input:

744457559

output:

43

result:

ok good solution

Test #193:

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

input:

117979097

output:

3

result:

ok good solution

Test #194:

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

input:

910461493

output:

5

result:

ok good solution

Test #195:

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

input:

796412147

output:

2

result:

ok good solution

Test #196:

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

input:

221019493

output:

2

result:

ok good solution

Test #197:

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

input:

237830497

output:

10

result:

ok good solution

Test #198:

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

input:

209079863

output:

5

result:

ok good solution

Test #199:

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

input:

808345841

output:

3

result:

ok good solution

Test #200:

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

input:

100217503

output:

3

result:

ok good solution

Test #201:

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

input:

99546341

output:

2

result:

ok good solution

Test #202:

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

input:

811108069

output:

6

result:

ok good solution

Test #203:

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

input:

121875503

output:

5

result:

ok good solution

Test #204:

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

input:

932569537

output:

10

result:

ok good solution

Test #205:

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

input:

598983901

output:

6

result:

ok good solution

Test #206:

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

input:

54645551

output:

7

result:

ok good solution

Test #207:

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

input:

22252519

output:

3

result:

ok good solution

Test #208:

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

input:

666436031

output:

14

result:

ok good solution

Test #209:

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

input:

900871603

output:

2

result:

ok good solution

Test #210:

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

input:

561111223

output:

43

result:

ok good solution

Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #6:

0%

Subtask #10:

score: 0
Skipped

Dependency #9:

0%