結果

問題 No.1126 SUM
ユーザー ikkunjyanaikaikkunjyanaika
提出日時 2020-10-15 15:50:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 1,000 ms
コード長 2,410 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 198,588 KB
実行使用メモリ 27,020 KB
最終ジャッジ日時 2023-09-28 01:10:10
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
26,772 KB
testcase_01 AC 33 ms
26,812 KB
testcase_02 AC 32 ms
26,908 KB
testcase_03 AC 32 ms
26,968 KB
testcase_04 AC 32 ms
27,020 KB
testcase_05 AC 32 ms
26,820 KB
testcase_06 AC 30 ms
26,804 KB
testcase_07 AC 31 ms
26,768 KB
testcase_08 AC 33 ms
26,808 KB
testcase_09 AC 34 ms
26,772 KB
testcase_10 AC 34 ms
26,812 KB
testcase_11 AC 31 ms
26,812 KB
testcase_12 AC 32 ms
26,884 KB
testcase_13 AC 32 ms
26,864 KB
testcase_14 AC 31 ms
26,752 KB
testcase_15 AC 31 ms
26,888 KB
testcase_16 AC 32 ms
26,864 KB
testcase_17 AC 32 ms
26,864 KB
testcase_18 AC 33 ms
26,804 KB
testcase_19 AC 32 ms
26,808 KB
testcase_20 AC 31 ms
26,968 KB
testcase_21 AC 32 ms
26,908 KB
testcase_22 AC 32 ms
26,796 KB
testcase_23 AC 32 ms
26,816 KB
testcase_24 AC 32 ms
26,752 KB
testcase_25 AC 32 ms
26,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define lb(x,a) lower_bound(all(x),a)
#define ub(x,a) upper_bound(all(x),a)
#define maxe(x,a) max_element(all(x))
#define mine(x,a) min_element(all(x))
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
const ll nmax=1000005;


ll fac[nmax],finv[nmax],inv[nmax];

void comint(){
 fac[0]=fac[1]=1;
 finv[0]=finv[1]=1;
 inv[1]=1;
 for(ll i=2;i<nmax;i++){
  fac[i]=fac[i-1]*i%mod;
  inv[i]=mod-inv[mod%i]*(mod/i)%mod;
  finv[i]=finv[i-1]*inv[i]%mod;
}
}

ll com(ll n, ll k){
 if(n<k||n<0||k<0) return 0;
 return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

void solve(){
  ll n,m;
  cin >> n >> m;
  mint ans=0;
  comint();
  rep(i,n,m+1) ans+=com(i,n);
  cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}
0