結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
4,352 KB
testcase_01 AC 139 ms
4,356 KB
testcase_02 AC 132 ms
4,356 KB
testcase_03 AC 132 ms
4,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 134 ms
4,356 KB
testcase_08 WA -
testcase_09 AC 133 ms
4,356 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 131 ms
4,352 KB
testcase_17 AC 138 ms
4,356 KB
testcase_18 AC 135 ms
4,356 KB
testcase_19 AC 135 ms
4,356 KB
testcase_20 AC 138 ms
4,356 KB
testcase_21 AC 140 ms
4,356 KB
testcase_22 AC 133 ms
4,356 KB
testcase_23 AC 135 ms
4,356 KB
testcase_24 AC 137 ms
4,352 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 135 ms
4,356 KB
testcase_30 AC 137 ms
4,356 KB
testcase_31 WA -
testcase_32 AC 146 ms
4,356 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 132 ms
4,356 KB
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;
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]+1) return modpow(a,t,m);
	return modpow(a,phi[m] + (H4M(a,b-1,phi[m]) - phi[m]) % 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