結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー kusaf_kusaf_
提出日時 2024-02-26 20:21:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 3,011 ms
コンパイル使用メモリ 255,568 KB
実行使用メモリ 10,228 KB
最終ジャッジ日時 2024-02-26 20:21:56
合計ジャッジ時間 7,446 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 148 ms
6,676 KB
testcase_02 AC 151 ms
6,676 KB
testcase_03 AC 155 ms
6,676 KB
testcase_04 AC 156 ms
6,676 KB
testcase_05 AC 261 ms
6,676 KB
testcase_06 AC 262 ms
6,676 KB
testcase_07 AC 14 ms
6,676 KB
testcase_08 AC 16 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 23 ms
7,544 KB
testcase_14 AC 23 ms
7,076 KB
testcase_15 AC 21 ms
7,084 KB
testcase_16 AC 21 ms
6,676 KB
testcase_17 AC 21 ms
10,228 KB
testcase_18 AC 20 ms
7,348 KB
testcase_19 AC 21 ms
7,964 KB
testcase_20 AC 22 ms
9,448 KB
testcase_21 AC 20 ms
7,192 KB
testcase_22 AC 21 ms
7,944 KB
testcase_23 AC 20 ms
9,084 KB
testcase_24 AC 21 ms
9,472 KB
testcase_25 AC 22 ms
9,472 KB
testcase_26 AC 21 ms
9,472 KB
testcase_27 AC 21 ms
9,084 KB
testcase_28 AC 22 ms
9,084 KB
testcase_29 AC 22 ms
9,472 KB
testcase_30 AC 23 ms
9,472 KB
testcase_31 AC 23 ms
9,472 KB
testcase_32 AC 22 ms
9,084 KB
testcase_33 AC 21 ms
9,472 KB
testcase_34 AC 147 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
  string N;
  ll M;
  cin >> N >> M;

  auto inc = [&](string s) {
    ranges::reverse(s);
    s += '0';
    for(auto &i : s) {
      if(i != '9') {
        i++;
        break;
      }
      else { i = '0'; }
    }
    ranges::reverse(s);
    return s;
  };

  auto div = [&](string s) {
    ll n = s.size();
    vector<ll> v;
    for(auto &i : s) { v.emplace_back(i - '0'); }
    string r = "";
    for(ll i = 0; i < n; i++) {
      r += char(v[i] / 2 + '0');
      if(v[i] & 1) { v[i + 1] += 10; }
    }
    return r;
  };

  auto rem = [&](string s) {
    ll r = 0;
    for(auto &i : s) {
      r *= 10;
      r += (i - '0');
      r %= M;
    }
    return r;
  };

  if((N.back() - '0') & 1) { cout << rem(N) * rem(div(inc(N))) % M << "\n"; }
  else { cout << rem(inc(N)) * rem(div(N)) % M << "\n"; }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll t;
  cin >> t;
  while(t--) { solve(); }
}
0