結果
問題 |
No.181 A↑↑N mod M
|
ユーザー |
![]() |
提出日時 | 2018-11-15 13:49:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 5,000 ms |
コード長 | 1,822 bytes |
コンパイル時間 | 2,213 ms |
コンパイル使用メモリ | 198,548 KB |
最終ジャッジ日時 | 2025-01-06 16:41:01 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 37 |
コンパイルメッセージ
main.cpp: In function ‘int SPOJ_MTETRA()’: main.cpp:87:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 87 | scanf("%lld",&T); | ~~~~~^~~~~~~~~~~ main.cpp:90:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 90 | scanf("%lld %lld %lld",&a,&n,&m); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; 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;} //BEGIN CUT HERE Int phi(Int n){ Int res=n; for(Int i=2;i*i<=n;i++){ if(n%i==0){ res=res/i*(i-1); for(;n%i==0;n/=i); } } if(n!=1) res=res/n*(n-1); return res; } Int mpow(Int a,Int n,Int m,Int &f){ using ull = unsigned long long; if(a==1||n==0) return 1; ull v=1,x=a,z=m; f|=x>=z; x%=m; while(1){ if(n&1) v*=x; if(v>=z) f=1,v%=m; n>>=1; if(!n) break; x=x*x; if(x>=z) f=1,x%=m; } return v; } Int mtetra(Int a,Int n,Int m,Int &f){ if(a==0) return ~n&1; if(m==1) return f=1; if(a==1||n==0) return 1; if(n==1){ f|=a>=m; return a%m+f*m; } Int z=mtetra(a,n-1,phi(m),f); Int r=mpow(a,z,m,f); return r+f*m; } //END CUT HERE //INSERT ABOVE HERE signed YUKI_181(){ Int a,n,m,f=0; cin>>a>>n>>m; cout<<mtetra(a,n,m,f)%m<<endl; return 0; } /* verified on 2018/11/15 https://yukicoder.me/problems/no/181 */ signed SPOJ_POWTOW(){ Int T; cin>>T; while(T--){ Int a,n,f=0; cin>>a>>n; stringstream ss; ss<<mtetra(a,n,1e9,f)%Int(1e9); auto s=ss.str(); if(f){ while(s.size()<9u) s='0'+s; cout<<"..."<<s<<endl; }else{ cout<<s<<endl; } } return 0; } /* verified on 2018/11/15 https://www.spoj.com/problems/POWTOW/ */ signed SPOJ_MTETRA(){ Int T; scanf("%lld",&T); while(T--){ Int a,n,m,f=0; scanf("%lld %lld %lld",&a,&n,&m); printf("%lld\n",mtetra(a,n,m,f)%m); } return 0; } /* verified on 2018/11/15 https://www.spoj.com/problems/MTETRA/ */ signed main(){ YUKI_181(); //SPOJ_POWTOW(); //SPOJ_MTETRA(); }