結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー furafura
提出日時 2020-10-10 01:47:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,171 bytes
コンパイル時間 2,849 ms
コンパイル使用メモリ 205,236 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 20:52:16
合計ジャッジ時間 3,444 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 36 ms
4,380 KB
testcase_09 AC 37 ms
4,376 KB
testcase_10 AC 38 ms
4,376 KB
testcase_11 AC 37 ms
4,376 KB
testcase_12 AC 38 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 87 ms
4,376 KB
testcase_15 AC 37 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// OEIS A002326

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

lint modpow(lint a,lint k,int m){
	lint r=1%m;
	for(lint x=a%m;k>0;k>>=1,x=x*x%m) if(k&1) r=r*x%m;
	return r;
}

vector<long long> divisors(long long a){
	vector<long long> res;
	for(long long i=1;i*i<=a;i++) if(a%i==0) {
		res.emplace_back(i);
		if(i*i<a) res.emplace_back(a/i);
	}
	sort(res.begin(),res.end());
	return res;
}

lint phi(lint a){
	lint res=a;
	for(lint p=2;p*p<=a;p++) if(a%p==0) {
		res=res/p*(p-1);
		do{ a/=p; }while(a%p==0);
	}
	if(a>1) res=res/a*(a-1);
	return res;
}

void solve(){
	int n; scanf("%d",&n);
	for(lint d:divisors(phi(2*n-1))){
		if(modpow(2,d,2*n-1)==1){
			printf("%lld\n",d);
			break;
		}
	}
}

int main(){
// experiment
/*
	for(int n=1;n<30;n++){
		auto f=[&](vector<int> p){
			vector<int> q(2*n);
			rep(i,n){
				q[2*i]=p[i];
				q[2*i+1]=p[n+i];
			}
			return q;
		};

		vector<int> p(2*n);
		iota(p.begin(),p.end(),0);
		auto p0=p;
		int cnt=0;
		while(1){
			p=f(p);
			cnt++;
			if(p==p0) break;
		}
		printf("n = %2d: %d\n",n,cnt);
	}
*/
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0