結果
| 問題 |
No.1255 ハイレーツ・オブ・ボリビアン
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-10-09 22:10:53 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,197 bytes |
| コンパイル時間 | 6,273 ms |
| コンパイル使用メモリ | 248,696 KB |
| 最終ジャッジ日時 | 2025-01-15 04:50:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:88:20: error: reference to 'identity' is ambiguous
88 | vector<Int> as=identity(2*n);
| ^~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/iterator_concepts.h:38,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_iterator_base_types.h:71,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_algobase.h:65,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/specfun.h:45,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/cmath:1935,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:41,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/ranges_cmp.h:47:10: note: candidates are: 'struct std::identity'
47 | struct identity
| ^~~~~~~~
main.cpp:17:13: note: 'std::vector<long long int> identity(Int)'
17 | vector<Int> identity(Int n){
| ^~~~~~~~
main.cpp:97:16: error: reference to 'identity' is ambiguous
97 | }while(as!=identity(2*n));
| ^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/ranges_cmp.h:47:10: note: candidates are: 'struct std::identity'
47 | struct identity
| ^~~~~~~~
main.cpp:17:13: note: 'std::vector<long long int> identity(Int)'
17 | vector<Int> identity(Int n){
| ^~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const char newl = '\n';
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
vector<Int> identity(Int n){
vector<Int> ord(n);
iota(ord.begin(),ord.end(),0);
return ord;
}
template<typename T>
T mod_pow(T a,long long n,T mod){
using ll = long long;
T res(1);
while(n){
if(n&1) res=(ll)res*a%mod;
a=(ll)a*a%mod;
n>>=1;
}
return res;
}
// min m s.t. a^m = 1 mod n (a, n are coprime)
template<typename T>
T carmichael_lambda(T n){
auto lcm=[](auto a,auto b){return a/__gcd(a,b)*b;};
T res=1;
if(n%8==0) n/=2;
for(int i=2;i*i<=n;i++){
if(n%i==0){
T tmp=i-1;
for(n/=i;n%i==0;n/=i) tmp*=i;
res=lcm(res,tmp);
}
}
if(n!=1) res=lcm(res,n-1);
return res;
}
template<typename T>
T order(T x,T MOD){
T res=carmichael_lambda(MOD);
vector<T> cand;
for(T i=1;i*i<=res;i++){
if(res%i) continue;
cand.emplace_back(i);
cand.emplace_back(res/i);
}
sort(cand.begin(),cand.end());
for(T c:cand)
if(mod_pow(x,c,MOD)==1) return c;
return res;
}
//INSERT ABOVE HERE
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
auto solve=[](Int n){
return order<Int>(2,2*n-1);
/*
Int res=0,tmp=1;
do{
tmp+=2*n-1;
while(tmp%2==0) tmp/=2,res++;
}while(tmp!=1);
return res;
*/
};
auto naive=[&](Int n){
vector<Int> as=identity(2*n);
Int cnt=0;
do{
cnt++;
vector<Int> bs(as);
for(Int i=0;i<n;i++){
as[i*2+0]=bs[0+i];
as[i*2+1]=bs[n+i];
}
}while(as!=identity(2*n));
return cnt;
};
const Int EXPERIMENT = 0;
if(EXPERIMENT){
for(Int n=1;n<=30;n++){
cout<<n<<':'<<naive(n)<<':'<<solve(n)<<newl;
assert(naive(n)==solve(n));
}
}
Int T;
cin>>T;
while(T--){
Int n;
cin>>n;
cout<<solve(n)<<newl;
}
return 0;
}
beet