結果

問題 No.2193 メガの下1桁
ユーザー SSRSSSRS
提出日時 2023-01-13 22:34:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,792 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 177,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 04:17:47
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const array<int, 11> MODS = {3960, 960, 256, 128, 64, 32, 16, 8, 4, 2, 1};
int modulo(int a, int m){
  if (a < m){
    return a;
  } else {
    return a % m + m;
  }
}
int modpow(int a, int b, int m){
  int ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans = modulo(ans * a, m);
      ans %= m;
    }
    a = modulo(a * a, m);
    b /= 2;
  }
  return ans;
}
array<int, 11> modpow(array<int, 11> a, array<int, 11> b){
  array<int, 11> c;
  for (int i = 0; i < 10; i++){
    c[i] = modpow(a[i], b[i + 1], MODS[i]);
  }
  if (a[0] == 0 && b[0] > 0){
    c[10] = 0;
  } else {
    c[10] = 1;
  }
  return c;
}
array<int, 11> get(long long x){
  array<int, 11> A;
  for (int i = 0; i < 11; i++){
    A[i] = modulo(x, MODS[i]);
  }
  return A;
}
array<int, 11> operator +(array<int, 11> A, array<int, 11> B){
  array<int, 11> C;
  for (int i = 0; i < 11; i++){
    C[i] = modulo(A[i] + B[i], MODS[i]);
  }
  return C;
}
int main(){
  long long M;
  cin >> M;
  long long D;
  cin >> D;
  long long N;
  cin >> N;
  int B;
  cin >> B;
  if (M == 0 && D == 0){
    if (N % 2 == 0){
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  } else {
    array<int, 11> m = get(M);
    array<int, 11> d = get(D);
    map<array<int, 11>, int> mp;
    mp[m] = 0;
    vector<array<int, 11>> h = {m};
    int t = 0;
    int ans;
    while (true){
      if (t == N){
        ans = m[0] % B;
        break;
      }
      t++;
      m = modpow(m + d, m);
      h.push_back(m);
      if (mp.count(m) == 1){
        int t2 = mp[m];
        int p = (N - t2) % (t - t2) + t2;
        ans = h[p][0] % B;
        break;
      }
      mp[m] = t;
    }
    if (ans < 10){
      cout << ans << endl;
    } else {
      cout << 'A' << endl;
    }
  }
}
0