結果

問題 No.984 Inversion
ユーザー 👑 kmjpkmjp
提出日時 2020-02-11 23:42:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,537 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 175,248 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-07-24 17:08:39
合計ジャッジ時間 6,268 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 16 ms
4,412 KB
testcase_03 AC 26 ms
5,100 KB
testcase_04 AC 20 ms
4,628 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 4 ms
4,384 KB
testcase_08 AC 25 ms
4,800 KB
testcase_09 AC 39 ms
5,492 KB
testcase_10 AC 43 ms
5,320 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 19 ms
4,384 KB
testcase_13 AC 18 ms
5,092 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 34 ms
5,520 KB
testcase_16 AC 19 ms
5,236 KB
testcase_17 AC 34 ms
5,240 KB
testcase_18 AC 45 ms
5,256 KB
testcase_19 AC 19 ms
4,964 KB
testcase_20 AC 49 ms
5,504 KB
testcase_21 AC 44 ms
5,476 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,P,mo;

ll modpow(ll a, ll n = mo-2, ll mo=mo) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll modlog(int g,int a) {  // return g^x=a mod a
	map<int,int> M;
	ll cur=1;
	int sq=sqrt(mo);
	int i;
	FOR(i,sq) {
		M[cur]=i;
		cur=cur*g%mo;
	}
	
	ll step=cur;
	cur=1;
	ll num=0;
	int lp=0;
	while(1) {
		ll x=a*modpow(cur)%mo;
		if(lp++>sq+5) return 1LL<<50;
		if(M.count(x)) return num+M[x];
		cur=cur*step%mo;
		num+=sq;
	}
}

int get_prim(int p) { //primitive element of prime p
	int q=p-1;
	vector<int> V;
	int x;
	for(x=2;x*x<=p;x++) if(q%x==0) V.push_back(x),V.push_back(q/x);
	
	for(x=2;;x++) {
		int ng=0;
		FORR(v,V) if(modpow(x,v,p)==1) ng=1;
		if(ng==0) return x;
	}
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	
	cin>>P>>N;
	mo=P;
	if(N==1 || P==2) return _P("0\n");
	
	x=modlog(get_prim(P),N);
	cout<<x%2<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0