結果

問題 No.793 うし数列 2
ユーザー cherrypi59
提出日時 2019-04-18 09:53:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 167,684 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 08:48:12
合計ジャッジ時間 2,748 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

const lint MOD = (lint)1e9 + 7;
lint pre[65];

lint mod_pow(lint n, lint x){
    lint res = 1;
    while(x){
        if(x & 1) res = res * n % MOD;
        x >>= 1; n = n * n % MOD;
    }
    return res;
}

int main(){
    lint N; cin >> N;

    pre[0] = 3;
    for(int i=1;(1LL<<i)<=N;i++){
        pre[i] = pre[i-1] * mod_pow(10, 1LL<<(i-1)) + pre[i-1];
        pre[i] %= MOD;
    }

    lint ans = mod_pow(10, N), cur = 0;
    for(int i=0;0<N;i++){
        if(N & 1){
            ans += pre[i] * mod_pow(10, cur);
            ans %= MOD; cur += (1LL<<i);
        }
        N >>= 1;
    }

    cout << ans << endl;
    return 0;
}
0