結果

問題 No.251 大きな桁の復習問題(1)
ユーザー kyuridenamidakyuridenamida
提出日時 2015-07-24 22:35:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,714 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 145,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 16:47:28
合計ジャッジ時間 2,410 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b){
	return b ? gcd(b,a%b) : a;
}
long long lcm(long long a,long long b){
	return a / gcd(a,b) * b;
}

long long mul(long long a,long long b,const long long mod){
	return b?(mul(a*2,b/2,mod)+(b&1?a:0))%mod:0;
}

long long bpow(long long a,long long b,const long long mod){
	return (b?bpow(a*a%mod,b/2,mod)*(b&1?a:1):1)%mod;
}

long long inv(long long a,const long long mod){
	return bpow(a,mod-2,mod);
}

// to overflow
/*long long bpow(long long a,long long b,const long long mod){
	return (b?mul(bpow(mul(a,a,mod),b/2,mod),(b&1?a:1),mod):1)%mod;
}*/
class mInt{
public:
	static const long long mod = 1000000007;
	long long v;
	mInt():v(0){}
	mInt(long long v):v((v%mod+mod)%mod){}
};
mInt& operator += (mInt &a,mInt b){ return a = a.v + b.v; }
mInt& operator -= (mInt &a,mInt b){ return a = a.v - b.v; }
mInt& operator *= (mInt &a,mInt b){ return a = a.v * b.v; }
mInt& operator /= (mInt &a,mInt b){ return a = a.v * inv(b.v,mInt::mod); }
mInt operator + (mInt a,mInt b){ return a += b; }
mInt operator - (mInt a,mInt b){ return a -= b; }
mInt operator * (mInt a,mInt b){ return a *= b; }
mInt operator / (mInt a,mInt b){ return a /= b; }
ostream& operator<<(ostream& os, const mInt& x){ return os << x.v; }

int main(){
	int A = 129402307;
	int B = 129402306;
	long long n = 0, m = 0;
	string a,b;
	cin >> a >> b;
	for(int i = 0 ; i < a.size() ; i++) n = (n * 10 + a[i] - '0') % A;
	for(int i = 0 ; i < b.size() ; i++) m = (m * 10 + b[i] - '0') % B;
	
	if( a[0] == '0' ){
		cout << 0 << endl;
	}else{
		if( n == 0 && m == 0 && b[0] != '0' ){
			cout << 0 << endl;
		}else{
			cout << bpow(n,m,A) << endl;
		}
	}
}














0