結果

問題 No.793 うし数列 2
ユーザー ei1333333ei1333333
提出日時 2018-10-27 23:52:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 690 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 200,072 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-29 22:18:53
合計ジャッジ時間 5,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 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 6 ms
5,376 KB
testcase_06 AC 15 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 17 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;
const int64 mod = 1e9 + 7;

using pi = pair< int, int >;

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

int64 rec(int64 length, int64 weight, bool l) {
  if(length == 1) return l ? weight : 3 * weight % mod;
  int64 mid = length >> 1;
  int64 ret = 0;
  (ret += rec(mid, weight, false)) %= mod;
  (ret += rec(length - mid, weight * power(10, mid) % mod, l)) %= mod;
  return ret;
}

int main() {
  int64 N;
  cin >> N;
  assert(1LL <= N && N <= 1000000000000000000LL);
  cout << rec(N + 1, 1, true) << endl;
}
0