fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7.  
  8. const int INF = 1e9;
  9. const ll LINF = 1e18;
  10.  
  11. struct BigInt {
  12. static const int BASE = 1e9;
  13. static const int B = 9;
  14.  
  15. vector<int> a;
  16.  
  17. BigInt() {}
  18.  
  19. BigInt(ll x) {
  20. for (; x > 0; x /= BASE) {
  21. a.push_back(x % BASE);
  22. }
  23. }
  24.  
  25. BigInt(const string &s) {
  26. for (int i = (int)s.size() - 1; i >= 0; i -= B) {
  27. int beg = max(0, i - B + 1);
  28. int len = i - beg + 1;
  29. int block = stoi(s.substr(beg, len));
  30. a.push_back(block);
  31. }
  32. trim();
  33. }
  34.  
  35. void trim() {
  36. while (!a.empty() && a.back() == 0) {
  37. a.pop_back();
  38. }
  39. }
  40.  
  41. bool isZero() {
  42. return (a.empty());
  43. }
  44.  
  45. BigInt operator*=(const BigInt &other) {
  46. int n = a.size(), m = other.a.size();
  47. vector<int> c(n + m, 0);
  48. for (int i = 0; i < n; i++) {
  49. int carry = 0;
  50. for (int j = 0; j < m || carry; j++) {
  51. ll cur = c[i + j] + 1ll * a[i] * (j < m ? other.a[j] : 0) + carry;
  52. c[i + j] = cur % BASE;
  53. carry = cur / BASE;
  54. }
  55. }
  56. swap(a, c);
  57. trim();
  58. return *this;
  59. }
  60.  
  61. BigInt operator*(const BigInt &other) const {
  62. return BigInt(*this) *= other;
  63. }
  64.  
  65. friend istream& operator>>(istream &in, BigInt &num) {
  66. string s;
  67. in >> s;
  68. num = BigInt(s);
  69. return in;
  70. }
  71.  
  72. friend ostream& operator<<(ostream &out, const BigInt &num) {
  73. if (num.a.empty()) {
  74. return out << 0;
  75. }
  76. string s = to_string(num.a.back());
  77. for (int i = (int)num.a.size() - 2; i >= 0; i--) {
  78. string block = to_string(num.a[i]);
  79. while (block.size() < 9) block = '0' + block;
  80. s += block;
  81. }
  82. for (int i = 0; i < s.size(); i++) {
  83. out << s[i];
  84. if ((i + 1) % 70 == 0) out << '\n';
  85. }
  86. return out;
  87. }
  88. };
  89.  
  90. BigInt binpow(BigInt a, int b) {
  91. BigInt ans = 1;
  92. for (; b > 0; b >>= 1) {
  93. if (b & 1) ans = ans * a;
  94. a = a * a;
  95. }
  96. return ans;
  97. }
  98.  
  99. int main() {
  100. ios::sync_with_stdio(false);
  101. cin.tie(nullptr);
  102. BigInt n;
  103. int p;
  104. cin >> n >> p;
  105. cout << binpow(n, p);
  106. }
  107.  
Success #stdin #stdout 0.01s 5288KB
stdin
2 15
stdout
32768