結果

問題 No.1281 Cigarette Distribution
ユーザー kappybarkappybar
提出日時 2020-11-06 22:30:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 2,220 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 165,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 19:10:42
合計ジャッジ時間 4,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 77 ms
4,376 KB
testcase_13 AC 184 ms
4,380 KB
testcase_14 AC 134 ms
4,380 KB
testcase_15 AC 90 ms
4,380 KB
testcase_16 AC 115 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 305 ms
4,376 KB
testcase_19 AC 302 ms
4,376 KB
testcase_20 AC 304 ms
4,380 KB
testcase_21 AC 150 ms
4,380 KB
testcase_22 AC 190 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        ModInt b=*this;
        while(n>0){
            if(n&1) a*=b;
            b*=b;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

int main(){
    ll n,m;
    cin >> n >> m;
    for(ll i=1;i<=m;i++){
        if(i == 1){
            cout << n << endl;
            continue;
        }
        if(i >= n-1){
            cout << 0 << endl;
            continue;
        }
        mint res = 1;
        ll s = (n+1) / i;
        ll r = (n+1) % i;
        res *= mint(s+1).pow(r);
        res *= mint(s).pow(i-r-1);
        res *= s-1;
        cout << res << endl;
    }
    return 0;
}
0