結果

問題 No.793 うし数列 2
ユーザー rogi52rogi52
提出日時 2022-10-04 22:27:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 191,880 KB
最終ジャッジ日時 2025-02-07 21:30:31
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll mod = 1e9+7;

ll modinv(ll a){
    if(a==0) abort();
    ll b = mod, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t * b; swap(a,b);
        u -= t * v; swap(u,v);
    }
    u %= mod;
    if(u<0) u += mod;
    return u;
}

ll modpow(ll a,ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    // 10^N + (10^N - 1) / 3
    ll N; cin >> N;
    cout << (modpow(10, N) + (modpow(10, N) - 1) * modinv(3) % mod) % mod << endl;
}
0