結果

問題 No.802 だいたい等差数列
コンテスト
ユーザー vjudge1
提出日時 2026-06-19 11:37:33
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 865 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,124 ms
コンパイル使用メモリ 180,184 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-19 11:37:36
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

long long qp(long long a, long long b, long long c) {
    a %= c;
    long long r = 1;
    while (b) {
        if (b & 1) r = r * a % c;
        a = a * a % c;
        b >>= 1;
    }
    return r;
}

int main() {
    long long n, m, d1, d2;
    cin >> n >> m >> d1 >> d2;
    if (n == 1) {
        cout << m % mod << endl;
        return 0;
    }
    if (m - 1 < (n - 1) * d1) {
        cout << 0 << endl;
        return 0;
    }
    if (d2 < d1) {
        cout << 0 << endl;
        return 0;
    }
    long long x = 2LL * m - (n - 1) * (d1 + d2);
    x %= mod;
    if (x < 0) x += mod;
    long long b = d2 - d1 + 1;
    long long p = qp(b, n - 1, mod);
    long long i2 = (mod + 1) / 2;
    long long a = x * p % mod;
    a = a * i2 % mod;
    cout << a << endl;;;
    return 0;
}
0