結果

問題 No.793 うし数列 2
ユーザー ei1333333ei1333333
提出日時 2018-10-28 00:26:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 201,492 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 22:18:56
合計ジャッジ時間 2,911 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int64 N, A[10000], L[10000], B;

int64_t mod_pow(int64_t x, int64_t n, int64_t mod) {
  int64_t ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}


int64 f(int64 x, int64 l, int length) {
  if(l == 1) return x % B;
  int64 ret = 0;
  int64 res = f(x, l / 2, length);
  if(l & 1) {
    ret += res;
    ret += res * mod_pow(10, (l / 2) * length, B) % B;
    ret %= B;
    ret += x * mod_pow(10, (l - 1) * length, B) % B;
  } else {
    ret += res;
    ret += res * mod_pow(10, (l / 2) * length, B) % B;
    ret %= B;
  }
  return ret;
}

int main() {

  // cin >> N;
  N = 2;
  A[0] = 1;
  L[0] = 1;
  A[1] = 3;
  cin >> L[1];
  B = 1e9 + 7;
  int64 ret = 0, sum = 0;
  for(int i = N - 1; i >= 0; i--) {
    int sz = (int) to_string(A[i]).size();
    (ret += f(A[i], L[i], sz) * mod_pow(10, sum, B) % B) %= B;
    sum += 1LL * sz * L[i];
  }
  cout << ret << endl;
}

0