結果

問題 No.251 大きな桁の復習問題(1)
ユーザー legosuke
提出日時 2018-03-10 05:55:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 727 bytes
コンパイル時間 1,428 ms
コンパイル使用メモリ 158,808 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 21:14:30
合計ジャッジ時間 2,630 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll mod = 129402307;
string N, M;

ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  ll n = 0;
  for (int i = 0; i < N.size(); i++) {
    n = (n * 10 + N[i] - '0') % mod;
  }
  if (M == "0") {
    cout << 1 << endl;
    return 0;
  }
  ll m = 0;
  for (int i = 0; i < M.size(); i++) {
    m = (m * 10 + M[i] - '0') % (mod - 1);
  }
  cout << (n == 0 ? 0 : mod_pow(n, m, mod)) << endl;

  return 0;
}
0