結果

問題 No.1918 Simple Math ?
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 23:27:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 78,140 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 15:03:02
合計ジャッジ時間 7,176 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 44 ms
4,380 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 10 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 32 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 38 ms
4,380 KB
testcase_13 AC 41 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 191 ms
4,376 KB
testcase_17 AC 205 ms
4,376 KB
testcase_18 AC 279 ms
4,380 KB
testcase_19 AC 297 ms
4,380 KB
testcase_20 AC 247 ms
4,376 KB
testcase_21 AC 421 ms
4,380 KB
testcase_22 AC 417 ms
4,376 KB
testcase_23 AC 415 ms
4,376 KB
testcase_24 AC 415 ms
4,376 KB
testcase_25 AC 418 ms
4,376 KB
testcase_26 AC 439 ms
4,376 KB
testcase_27 AC 441 ms
4,380 KB
testcase_28 AC 9 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 440 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){
    //cout << "a = " << a << " , N = " << N << endl;
    m32 ans = 0;
    for(i64 b=0; b<a; b++) if(b <= N){
        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