結果

問題 No.1281 Cigarette Distribution
ユーザー ShibuyapShibuyap
提出日時 2020-11-08 20:07:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,775 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 200,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 21:39:28
合計ジャッジ時間 5,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 76 ms
4,380 KB
testcase_13 AC 172 ms
4,380 KB
testcase_14 AC 127 ms
4,380 KB
testcase_15 AC 89 ms
4,376 KB
testcase_16 AC 110 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 283 ms
4,376 KB
testcase_19 AC 279 ms
4,380 KB
testcase_20 AC 274 ms
4,380 KB
testcase_21 AC 147 ms
4,376 KB
testcase_22 AC 182 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define srep(i,s,t) for (ll i = s; i < t; ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

const ll MOD = 1000000007;

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// ax + by = gcd(a, b) となるような (x, y) を求める
// a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰
    y -= a / b * x;
    return d;
}


// 負の数に対応した mod
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}


// 逆元計算 (a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // x % m だが、x が負かもしれないので
}

int main() {
    ll n, m;
    cin >> n >> m;
    srep(i,1,m+1){
        if(i == 1){
            cout << n << endl;
            continue;
        }
        if(n < i*2-1){
            cout << 0 << endl;
            continue;
        }
        ll a = n / i;
        ll b = n % i;
        ll ans = 1;
        if(b == i - 1){
            ans = mod_pow(a+1,i-1,MOD) * a % MOD;
        }else{
            ans = mod_pow(a+1,b+1,MOD) * (a-1) % MOD * mod_pow(a,i-(b+2),MOD) % MOD;
        }



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