結果

問題 No.665 Bernoulli Bernoulli
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-03-10 22:26:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 2,310 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 168,404 KB
実行使用メモリ 241,280 KB
最終ジャッジ日時 2024-04-22 18:28:31
合計ジャッジ時間 9,204 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 252 ms
241,280 KB
testcase_01 AC 272 ms
241,152 KB
testcase_02 AC 369 ms
241,280 KB
testcase_03 AC 369 ms
241,280 KB
testcase_04 AC 361 ms
241,152 KB
testcase_05 AC 354 ms
241,152 KB
testcase_06 AC 349 ms
241,152 KB
testcase_07 AC 349 ms
241,280 KB
testcase_08 AC 353 ms
241,280 KB
testcase_09 AC 361 ms
241,280 KB
testcase_10 AC 352 ms
241,280 KB
testcase_11 AC 367 ms
241,024 KB
testcase_12 AC 359 ms
241,280 KB
testcase_13 AC 371 ms
241,152 KB
testcase_14 AC 370 ms
241,152 KB
testcase_15 AC 352 ms
241,152 KB
testcase_16 AC 356 ms
241,152 KB
testcase_17 AC 352 ms
241,152 KB
testcase_18 AC 349 ms
241,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int mod, int N> class Faulhaber {
    int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
    int mul(int x, int y) { return 1LL * x * y % mod; }
    int sub(int x, int y) { return add(x, mod - y); }
    int modpow(int a, long long b) { int ret = 1; while (b > 0) { 
    if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
    int modinv(int a) { return modpow(a, mod - 2); }
    int div(int x, int y) { return mul(x, modinv(y)); }
    int C[N][N];
public:
    Faulhaber(){rep(i,0,N){C[i][0]=1;rep(j,1,i+1)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;}}
    // 1^m + 2^m + ... + n^m
    int F(int n, int m) {
        if(!m)return n;vector<int> dp(m+1);dp[0]=n;rep(k,1,m+1){int sm=sub(modpow(n+1,k+1),1);
        rep(i,0,k)sm=sub(sm,mul(dp[i],C[k+1][i]));dp[k]=div(sm,k+1);}return dp[m];}
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




const int mod = 1000000007;
Faulhaber<mod, 10101> f;
ll n; int k;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> n >> k;
    n %= mod;

    cout << f.F(n, k) << endl;
}
0