結果

問題 No.181 A↑↑N mod M
ユーザー beetbeet
提出日時 2018-11-14 20:40:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 972 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 198,992 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-26 01:12:09
合計ジャッジ時間 4,774 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 x,Int n,Int m,Int &flg){
  if(x==1||n==0) return 1;
  Int v=1;
  flg|=x>=m;
  x%=m;
  while(n){
    if(n&1) v*=x;
    if(v>=m) flg=1,v%=m;    
    x=x*x%m;
    n>>=1;
  }
  return v+flg*m;
}

Int mtetra(Int a,Int n,Int m,Int &flg){
  if(m==1) return flg=!!a,0;
  if(n==0) return 1;
  if(n==1) return a;
  Int z=mtetra(a,n-1,phi(m),flg);
  return mpow(a,z+flg*m,m,flg);
}
//END CUT HERE
//INSERT ABOVE HERE

signed solve(){
  Int a,n,m;
  cin>>a>>n>>m;
  Int flg=0;
  cout<<mtetra(a,n,m,flg)%m<<endl;
  return 0;
}

signed main(){
  solve();
}
0