結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー どららどらら
提出日時 2020-10-09 23:49:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,412 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 172,996 KB
実行使用メモリ 5,916 KB
最終ジャッジ日時 2023-09-27 20:11:16
合計ジャッジ時間 6,691 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

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 gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}

ll modlog(ll a, ll b, ll p){
  ll g=1;
  for(ll i=p; i>0; i/=2){
    g *= a;
    g %= p;
  }
  g = gcd(g,p);
  ll t=1,c=0;
  while(t%g>0){
    if(t==b) return c;
    t *= a;
    t %= p;
    c++;
  }
  if(b%g > 0) return -1;

  t/=g;
  b/=g;

  ll n=p/g,h=0,gs=1;
  for(;h*h<n;h++){
    gs *= a;
    gs %= n;
  }
  unordered_map<ll,ll> bs;
  for(ll s=0,e=b;s<h;bs[e]=++s){
    e *= a;
    e %= n;
  }
  for(ll s=0,e=t;s<n;){
    e*=gs;
    e%=n;
    s+=h;
    if(bs.count(e) > 0) return c+s-bs[e];
  }
  return -1;
}

ll solve(ll N){
  if(N == 1) return 1;
  return modlog(2,1,2*N+1);
  
  vector<int> v;
  rep(i,2*N) v.push_back(i+1);

  rep(i,1000){
    //rep(j,v.size()) cout << v[j] << " "; cout << endl;    
    vector<int> w(v.size());
    rep(j,N){
      w[2*j] = v[j];
      w[2*j+1] = v[N+j];
    }
    swap(v, w);

    bool flg = true;
    rep(j,v.size()) if(j+1 != v[j]) flg = false;
    if(flg) return i+1;
  }
  
  return -1;
}

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

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