結果

問題 No.251 大きな桁の復習問題(1)
ユーザー alpha_virginisalpha_virginis
提出日時 2015-07-25 11:26:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 712 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 143,948 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 04:44:52
合計ジャッジ時間 2,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int main() {

  char N[1048576];
  char M[1048576];

  uint64_t p = 129402307;

  scanf("%s", N);
  scanf("%s", M);

  int N_size = strlen(N);
  int M_size = strlen(M);

  uint64_t n = 0;
  uint64_t m = 0;

  for(int i = 0; i < N_size; ++i) {
    n = (n * 10 + (N[i] - '0')) % p;
  }

  for(int i = 0; i < M_size; ++i) {
    m = (m * 10 + (M[i] - '0')) % (p - 1);
  }

  if( n == 0 ) {
    printf("0\n");
    return 0;
  }
  if( m == 0 ) {
    printf("1\n");
    return 0;
  }

  uint64_t ans = 1;
  while( m != 0 ) {
    if( (m & 0x01) != 0 ) {
      ans = (ans * n) % p;
    }
    n = (n * n) % p;
    m >>= 1;
  }
                           
  printf("%ld\n", ans);
  
  return 0;
}
0