結果
問題 | No.181 A↑↑N mod M |
ユーザー |
![]() |
提出日時 | 2021-11-04 04:52:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 844 bytes |
コンパイル時間 | 5,023 ms |
コンパイル使用メモリ | 249,592 KB |
最終ジャッジ日時 | 2025-01-25 11:17:24 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 35 WA * 2 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 long long get2(long long a,long long n,long long m){ if(n>=31)return -1; if(n==0)return 1LL; long long ret = 1LL; long long nxt = get2(a,n-1,m); if(get2(a,n-1,m)==-1)return -1; rep(i,nxt){ ret *= a; if(ret >= m)return -1; } return ret; } long long get(long long a,long long n,long long m){ if(a==0)return 0; if(a==1)return 1%m; if(m==1)return 0; if(n==0)return 1%m; long long cnt =0; for(int i=1;i<=m;i++){ if(gcd(i,m)==1)cnt++; } long long t = get2(a,n,cnt); if(t!=-1)return t%m; return pow_mod(a,cnt + get(a,n-1,cnt),m); } int main(){ int A,N,M; cin>>A>>N>>M; cout<<get(A,N,M)<<endl; return 0; }