結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー tnakao0123tnakao0123
提出日時 2024-04-25 15:31:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 56,208 KB
実行使用メモリ 9,220 KB
最終ジャッジ日時 2024-04-25 15:31:38
合計ジャッジ時間 4,101 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 128 ms
6,940 KB
testcase_02 AC 120 ms
6,940 KB
testcase_03 AC 119 ms
6,944 KB
testcase_04 AC 120 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 20 ms
7,168 KB
testcase_24 AC 20 ms
7,040 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 20 ms
6,944 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 91 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2649.cc:  No.2649 [Cherry 6th Tune C] Anthem Flower - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 4000000;

/* typedef */

typedef long long ll;
typedef vector<int> vi;

/* global variables */

char s[MAX_N + 4];

/* subroutines */

void printv(vi &a) {
  for (int i = a.size() - 1; i >= 0; i--) printf("%d", a[i]);
  putchar('\n');
}

void incv(vi &a) {
  int co = 1;
  for (auto &ai: a) {
    int di = ai + co;
    ai = di % 10;
    co = di / 10;
  }
  if (co > 0) a.push_back(co);
}

void divv(vi &a, int b) {
  int r = 0;
  for (int i = a.size() - 1; i >= 0; i--) {
    r = (r * 10 + a[i]);
    a[i] = r / b;
    r %= b;
  }
  while (! a.empty() && a.back() == 0) a.pop_back();
}

int modv(vi &a, int b) {
  int r = 0;
  for (int i = a.size() - 1; i >= 0; i--)
    r = (r * 10 + a[i]) % b;
  return r;
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int m;
    scanf("%s%d", s, &m);
    int n = strlen(s);

    vi a(n);
    for (int i = 0; i < n; i++) a[i] = s[n - 1 - i] - '0';

    vi b(a);
    incv(b);
    //printv(a), printv(b);

    if (! (a[0] & 1)) divv(a, 2);
    else divv(b, 2);
    //printv(a), printv(b);

    int ra = modv(a, m), rb = modv(b, m);
    int r = (ll)ra * rb % m;
    printf("%d\n", r);
  }

  return 0;
}
0