結果

問題 No.251 大きな桁の復習問題(1)
ユーザー nanasili
提出日時 2015-07-31 12:48:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,056 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 83,480 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 17:23:54
合計ジャッジ時間 1,425 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:59:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |   scanf("%s %s", n, m);
      |   ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

#define MODN 129402307

ll expoModN(ll a, ll b) {
  if (b == 1) return a;
  if (b == 0) return 1;
  ll t = (expoModN(a, b/2)%MODN);
  return (((t*t)%MODN)*(expoModN(a, b%2)%MODN))%MODN;
}

ll solve(char *n, char *m) {
  ll s = 0;
  for (int i = 0; n[i] != '\0'; i++) {
    s = (s*10+n[i]-'0')%MODN;
  }


  if (s == 0) {
    if (strcmp(m, "0") == 0) {
      return 1;
    }else {
      return 0;
    }
  }else {
    ll t = 0;
    for (int i = 0; m[i] != '\0'; i++) {
      t = (t*10+m[i]-'0')%(MODN-1);
    }
    return expoModN(s, t);
  }
}

int main() {
  char n[100001], m[100001];
  scanf("%s %s", n, m);
  printf("%lld\n", solve(n, m));
}
0