結果

問題 No.1918 Simple Math ?
ユーザー karinohitokarinohito
提出日時 2022-03-26 11:02:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 4,126 ms
コンパイル使用メモリ 260,036 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2023-09-11 11:31:15
合計ジャッジ時間 6,971 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,372 KB
testcase_01 AC 5 ms
7,260 KB
testcase_02 AC 5 ms
7,348 KB
testcase_03 AC 4 ms
7,260 KB
testcase_04 AC 5 ms
7,424 KB
testcase_05 AC 5 ms
7,316 KB
testcase_06 AC 17 ms
7,280 KB
testcase_07 AC 22 ms
7,280 KB
testcase_08 AC 14 ms
7,260 KB
testcase_09 AC 9 ms
7,240 KB
testcase_10 AC 16 ms
7,364 KB
testcase_11 AC 5 ms
7,256 KB
testcase_12 AC 20 ms
7,304 KB
testcase_13 AC 15 ms
7,320 KB
testcase_14 AC 11 ms
7,288 KB
testcase_15 AC 7 ms
7,420 KB
testcase_16 AC 54 ms
7,316 KB
testcase_17 AC 58 ms
7,364 KB
testcase_18 AC 76 ms
7,412 KB
testcase_19 AC 81 ms
7,348 KB
testcase_20 AC 68 ms
7,268 KB
testcase_21 AC 113 ms
7,324 KB
testcase_22 AC 111 ms
7,264 KB
testcase_23 AC 112 ms
7,316 KB
testcase_24 AC 110 ms
7,256 KB
testcase_25 AC 112 ms
7,280 KB
testcase_26 AC 118 ms
7,268 KB
testcase_27 AC 118 ms
7,280 KB
testcase_28 AC 71 ms
7,412 KB
testcase_29 AC 5 ms
7,240 KB
testcase_30 AC 4 ms
7,360 KB
testcase_31 AC 118 ms
7,304 KB
testcase_32 AC 4 ms
7,384 KB
testcase_33 AC 4 ms
7,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
ll A, N,T;
using mint = modint1000000007;
mint B[1000006];
ll sqrtz(ll N) {
    ll L = 0, R = 2e9;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;
}
mint f(ll m) {
    ll r = sqrtz(m * A);
    mint R = r;
    mint res = r * mint(m);
    mint D = R * (R - 1) * (2 * R + 5) / 6 - mint(r / A) * B[A] - B[r % A];
    return res - D / A;
}

int main() {
    cin >> T;
    while(T){
        cin >> A >> N;
        T--;
        for (ll i = 1; i <= A; i++)B[i] = B[i - 1] + ((i * i - 1) % A);
        cout << f(N).val() << endl;
    }
}
0