結果

問題 No.1918 Simple Math ?
ユーザー Duy Nguyễn TườngDuy Nguyễn Tường
提出日時 2023-02-14 01:08:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,042 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 200,280 KB
実行使用メモリ 18,492 KB
最終ジャッジ日時 2023-09-23 14:22:40
合計ジャッジ時間 14,165 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
10,784 KB
testcase_01 AC 6 ms
4,376 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 114 ms
10,792 KB
testcase_07 AC 130 ms
10,672 KB
testcase_08 AC 69 ms
8,644 KB
testcase_09 AC 38 ms
5,212 KB
testcase_10 AC 92 ms
6,944 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 108 ms
8,476 KB
testcase_13 AC 74 ms
9,692 KB
testcase_14 AC 47 ms
7,280 KB
testcase_15 AC 23 ms
4,376 KB
testcase_16 AC 383 ms
12,332 KB
testcase_17 AC 436 ms
12,776 KB
testcase_18 AC 625 ms
15,156 KB
testcase_19 AC 599 ms
15,280 KB
testcase_20 AC 520 ms
14,620 KB
testcase_21 AC 892 ms
18,492 KB
testcase_22 AC 903 ms
11,048 KB
testcase_23 AC 893 ms
11,100 KB
testcase_24 AC 907 ms
18,092 KB
testcase_25 AC 853 ms
18,196 KB
testcase_26 AC 1,042 ms
11,192 KB
testcase_27 AC 755 ms
11,316 KB
testcase_28 AC 447 ms
9,728 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 886 ms
11,168 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #cheatkhitacontre #khionhatoicheat
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long /*fuck int*/
using namespace std;
int mod = 1000000007;
int Sqrt(int x) {
    int ret = 0;
    for (int i = (1ll<<31); i >= 1; i>>=1) if ((ret+i)*(ret+i)<=x) ret += i;
    return ret;
}
void fix(int &a) {
    a %= mod;
}
int mul(int a, int b) {
    fix(a);
    fix(b);
    return (a*b)%mod;
}
int binpow(int a, int b) {
    int ret = 1;
    while (b) {
        if (b&1) ret = mul(ret,a);
        a = mul(a,a);
        b >>= 1;
    }
    return ret;
}
int Sum(int a, int b) {
    fix(a);
    fix(b);
    return (a+b+mod)%mod;
}
int sub(int a, int b) {
    fix(a);
    fix(b);
    return (a-b+mod)%mod;
}
int Div(int a, int b) {
    fix(a);
    fix(b);
    return mul(a,binpow(b,mod-2));
}
void solve() {
    int n, a, m, ss = 0, s = 0;
    cin >> a >> n;
    m = Sqrt(a*n);
    vector<int> dp(a+1,0);
    for (int i = 1; i <= a; i++) dp[i] = Sum(dp[i],(i*i-1)%a+1);
    for (int i = 1; i <= a; i++) s = Sum(s,dp[i]);
    for (int i = 1; i <= m%a; i++) ss = Sum(ss,dp[i]);
    cout << sub(mul(m,n),Div(sub(Div(mul(mul(m,m+1),2*m+1),6ll),Sum(mul(s,m/a),ss)),a)) << "\n";
}
signed main() {
	IOS;
	int TEST=1;
	cin >> TEST;
	while (TEST--) solve();
}
0