結果

問題 No.1918 Simple Math ?
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 23:24:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 79,312 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-11 15:00:06
合計ジャッジ時間 7,401 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
4,384 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 184 ms
4,380 KB
testcase_17 AC 198 ms
4,380 KB
testcase_18 AC 268 ms
4,384 KB
testcase_19 AC 287 ms
4,380 KB
testcase_20 AC 237 ms
4,508 KB
testcase_21 AC 407 ms
4,384 KB
testcase_22 AC 403 ms
4,380 KB
testcase_23 AC 401 ms
4,380 KB
testcase_24 AC 399 ms
4,380 KB
testcase_25 AC 403 ms
4,380 KB
testcase_26 AC 425 ms
4,380 KB
testcase_27 AC 425 ms
4,384 KB
testcase_28 WA -
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 424 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#include <atcoder/fenwicktree>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using m32 = atcoder::static_modint<1000000007>;


i64 isqrt(i64 x){
    i64 l = 0, r = 2001001001;
    while(l + 1 < r){
        i64 m = (l+r) / 2;
        if(m * m <= x) l = m; else r = m;
    }
    return l;
}

const m32 inv2 = m32(2).inv();
const m32 inv6 = m32(6).inv();

m32 linear_sum(i64 x){
    return m32(x) * (m32(x)+1) * inv2;
}
m32 square_sum(i64 x){
    return m32(x) * (m32(x)+1) * (m32(x)*2+1) * inv6;
}

// sum_{i=0}^N ceil(i*i/a)
m32 solve2(i64 a, i64 N){
    m32 ans = 0;
    for(i64 b=0; b<a; b++){
        i64 n = (N-b) / a;
        ans += square_sum(n) * a + linear_sum(n) * b * 2 + m32((b*b+a-1)/a)*(n+1);
    }
    return ans - N;
}

m32 solve(){
    i64 a, N; cin >> a >> N;
    i64 n = isqrt(a * N);
    m32 grid = m32(n) * m32(N);
    return grid - solve2(a, n);
}

int main(){
    int T; cin >> T;
    rep(t,T) cout << solve().val() << '\n';
    return 0;
}

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0