結果
問題 | No.1255 ハイレーツ・オブ・ボリビアン |
ユーザー |
|
提出日時 | 2020-10-09 22:22:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,914 bytes |
コンパイル時間 | 2,354 ms |
コンパイル使用メモリ | 208,356 KB |
最終ジャッジ日時 | 2025-01-15 05:04:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 WA * 8 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’: main.cpp:134:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘lint’ {aka ‘long long int’} [-Wformat=] 134 | printf("%d\n",d); | ~^ ~ | | | | int lint {aka long long int} | %lld main.cpp:126:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 126 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp: In function ‘int main()’: main.cpp:165:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 165 | int q; scanf("%d",&q); rep(_,q) solve(); | ~~~~~^~~~~~~~~
ソースコード
// OEIS A002326 #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; template<class R> class matrix{ vector<vector<R>> a; public: matrix(int n):a(n,vector<R>(n)){} matrix(int m,int n):a(m,vector<R>(n)){} matrix& operator+=(const matrix& A){ assert(h()==A.h() && w()==A.w()); int m=h(),n=w(); rep(i,m) rep(j,n) (*this)[i][j]+=A[i][j]; return *this; } matrix& operator-=(const matrix& A){ assert(h()==A.h() && w()==A.w()); int m=h(),n=w(); rep(i,m) rep(j,n) (*this)[i][j]-=A[i][j]; return *this; } matrix& operator*=(const matrix& A){ assert(w()==A.h()); int m=h(),n=w(),l=A.w(); matrix B(m,l); rep(i,m) rep(j,l) rep(k,n) B[i][j]+=(*this)[i][k]*A[k][j]; swap(*this,B); return *this; } matrix operator+(const matrix& A)const{ return matrix(*this)+=A; } matrix operator-(const matrix& A)const{ return matrix(*this)-=A; } matrix operator*(const matrix& A)const{ return matrix(*this)*=A; } const vector<R>& operator[](int i)const{ return a[i]; } vector<R>& operator[](int i){ return a[i]; } vector<R> operator*(const vector<R>& v)const{ assert(w()==v.size()); int m=h(),n=w(); vector<R> res(m); rep(i,m) rep(j,n) res[i]+=(*this)[i][j]*v[j]; return res; } int h()const{ return a.size(); } int w()const{ return a.empty()?0:a[0].size(); } static matrix identity(int n){ matrix I(n); rep(i,n) I[i][i]=R{1}; return I; } }; template<class R> matrix<R> pow(matrix<R> A,long long k){ assert(A.h()==A.w()); matrix<R> B=matrix<R>::identity(A.h()); for(;k>0;k>>=1){ if(k&1) B*=A; A*=A; } return B; } int MOD; class mint{ int x; public: mint():x(0){} mint(long long y){ x=y%MOD; if(x<0) x+=MOD; } mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; } mint& operator-=(const mint& m){ x-=m.x; if(x< 0) x+=MOD; return *this; } mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; } mint& operator/=(const mint& m){ return *this*=inverse(m); } mint operator+(const mint& m)const{ return mint(*this)+=m; } mint operator-(const mint& m)const{ return mint(*this)-=m; } mint operator*(const mint& m)const{ return mint(*this)*=m; } mint operator/(const mint& m)const{ return mint(*this)/=m; } mint operator-()const{ return -x; } friend mint inverse(const mint& m){ int a=m.x,b=MOD,u=1,v=0; while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return u; } friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=t; return is; } friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; } int to_int()const{ return x; } }; mint operator+(long long x,const mint& m){ return mint(x)+m; } mint operator-(long long x,const mint& m){ return mint(x)-m; } mint operator*(long long x,const mint& m){ return mint(x)*m; } mint operator/(long long x,const mint& m){ return mint(x)/m; } 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))){ MOD=2*n-1; matrix<mint> A(2); A[0][0]=2; A[0][1]=1; A[1][0]=0; A[1][1]=1; mint x=pow(A,d)[0][1]; if(x.to_int()==0){ printf("%d\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; }