結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー kiyoshi0205kiyoshi0205
提出日時 2020-10-09 22:55:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 2,860 bytes
コンパイル時間 2,625 ms
コンパイル使用メモリ 187,188 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 14:43:58
合計ジャッジ時間 3,711 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(x) cout<<x<<endl
#define printyes print("Yes")
#define printno print("No")
#define printYES print("YES")
#define printNO print("NO")
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI=acos(-1);
const double eps=1e-9;
template<class T,class E> ostream& operator<<(ostream& os,pair<T,E>& p){return os<<"{"<<p.first<<","<<p.second<<"}";}
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modpow(ll a,ll n,ll m=mod){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%m;
    a=a*a%m;
    n>>=1;
  }
  return res;
}
ll eulerphy(ll N){
  ll i,res=1;
  for(i=2;i*i<=N;i++){
    if(N%i==0){
      res*=i-1;
      while(N%i==0){N/=i;res*=i;}
      res/=i;
    }
  }
  if(N!=1){
    res*=N-1;
  }
  return res;
}
vec diviserlist(ll N){
  ll i;
  vec res;
  for(i=1;i*i<N;i++){
    if(N%i==0){
      res.eb(i);res.eb(N/i);
    }
  }
  if(i*i==N)res.eb(i);
  vsort(res);
  return res;
}
int main(){
  startupcpp();
  int codeforces;cin>>codeforces;while(codeforces--){
  ll N;
  cin>>N;
  if(N==1){
    print(1);
    continue;
  }
  N=N*2-1;
  ll K=eulerphy(N);
  // print(N<<" "<<K);
  vec v=diviserlist(K);
  for(auto x:v){
    if(modpow(2,x,N)==1){
      print(x);
      break;
    }
  }
}}
0