10^4๋ฅผ ๊ตฌํ ๋ 101010*10 ๋ณด๋ค๋ 10^2 * 10^2 ๊ฐ ๋ ๋น ๋ฅธ ๊ฒฝ์ฐ์์ ์๊ฐํ์ฌ ํ์ดํ๋ค.
a^b์ผ๋ b๊ฐ ํ์์ธ ๊ฒฝ์ฐ๋ a๋ฅผ ํ๋ฒ ๋ ๊ณฑํด์ค์ผ ํ๋ค.
#include <iostream>
#define ll unsigned long long int
#define mod 1000000007
using namespace std;
ll pow(ll a, ll b) {
if (b == 0) return 1;
else {
ll n = pow(a, b / 2);
ll temp = (n * n) % mod;
if (b % 2 == 0) return temp;
else return (temp * a) % mod;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll A, B; cin >> A >> B;
cout << pow(A%mod, B); //mod๋ก ๋จผ์ ๋๋ ์ฃผ๋๊ฒ ํต์ฌ.
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 1330๋ฒ - ๋ ์ ๋น๊ตํ๊ธฐ (0) | 2021.11.04 |
---|---|
[๋ฐฑ์ค,c++] 13241๋ฒ - ์ต์๊ณต๋ฐฐ์ (0) | 2021.11.04 |
[๋ฐฑ์ค,c++] 13239๋ฒ - Combinations (0) | 2021.11.04 |
[๋ฐฑ์ค,c++] 13163๋ฒ - ๋๋ค์์ ๊ฐ ๋ถ์ด๊ธฐ (0) | 2021.11.04 |
[๋ฐฑ์ค,c++] 1316๋ฒ - ๊ทธ๋ฃน ๋จ์ด ์ฒด์ปค (0) | 2021.11.04 |
[๋ฐฑ์ค,c++] 13023๋ฒ - ABCDE (0) | 2021.11.04 |
๋๊ธ