結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー どららどらら
提出日時 2020-10-10 11:12:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 172,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 14:47:36
合計ジャッジ時間 3,984 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll phi(ll n) {
  ll res = n;
  for(ll i = 2; i*i <= n; i++) {
    if (n % i == 0) {
      res -= res / i;
      while(n % i == 0)
        n /= i;
    }
  }
  if (n > 1)
    res -= res / n;
  return res;
}
vector<ll> divisor(ll n){
  vector<ll> ret;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i!=n/i) ret.push_back(n/i);
    }
  }
  sort(ALLOF(ret));
  return ret;
}
ll mod_pow(ll x, ll n, ll mod){
  ll res = 1;
  while(n>0){
    if(n&1) res = res*x%mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}


ll solve(ll N){
  if(N == 1) return 1;
  vector<ll> d = divisor(phi(2*N-1));

  rep(i,d.size()){
    ll x = d[i];

    if(mod_pow(2,x,2*N-1) == 1) return x;
  }
  
  return -1;
}

int main(){
  int T;
  cin >> T;

  rep(t,T){
    ll N;
    cin >> N;
    cout << solve(N) << endl;
  }
  
  return 0;
}

0