結果

問題 No.181 A↑↑N mod M
ユーザー 👑 kmjpkmjp
提出日時 2015-04-06 02:31:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,547 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 146,392 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 06:04:38
合計ジャッジ時間 8,173 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,N,M;

ll modpow(ll a, ll n, ll mo) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

const int Mmax=2000;
int phi[Mmax+20];

// return min(upbound,A^^B)
ll AtB(ll a,ll b,ll upbound) {
	if(b==0 || a==1) return min(upbound,1LL);
	if(b==1) return min(upbound,a);
	if(b==2) return (a>10)?upbound:min(modpow(a,a,1LL<<60),upbound);
	if(a==2 && b==3) return min(upbound,1LL<<4);
	if(a==3 && b==3) return min(upbound,modpow(3,27,1LL<<60));
	if(a==2 && b==4) return min(upbound,1LL<<16);
	return upbound;
}

ll H4M(ll a,ll b,ll m) {
	if(m==1) return 0;
	if(a==1 || b==0) return 1;
	
	ll t=AtB(a,b-1,phi[m]+1);
	if(t<=phi[m]) return modpow(a,t,m);
	return modpow(a,H4M(a,b-1,phi[m]), m);
}

void GetPhi() {
	int i,x;
	for(x=1;x<=Mmax;x++) for(i=1;i<=x;i++) phi[x]+=__gcd(i,x)==1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>N>>M;
	GetPhi();
	cout<< H4M(A,N,M) << endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0