結果

問題 No.1918 Simple Math ?
ユーザー i_am_noobi_am_noob
提出日時 2023-02-11 03:10:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 200,568 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 03:06:33
合計ジャッジ時間 6,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 15 ms
4,380 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 19 ms
4,380 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 54 ms
4,380 KB
testcase_17 AC 59 ms
4,376 KB
testcase_18 AC 79 ms
4,376 KB
testcase_19 AC 84 ms
4,376 KB
testcase_20 AC 70 ms
4,380 KB
testcase_21 AC 119 ms
4,376 KB
testcase_22 AC 118 ms
4,380 KB
testcase_23 AC 118 ms
4,376 KB
testcase_24 AC 118 ms
4,380 KB
testcase_25 AC 118 ms
4,376 KB
testcase_26 AC 124 ms
4,376 KB
testcase_27 AC 124 ms
4,380 KB
testcase_28 AC 73 ms
4,376 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 124 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int maxn=1000005,mod=1000000007;
int sub(int x, int y){x-=y; if(x<0) x+=mod; return x;}
int mul(int x, int y){return ((ll)x)*y%mod;}
int Pow(int x, int y=mod-2){int res=1; for(; y; x=mul(x,x),y>>=1) if(y&1) res=mul(res,x); return res;}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int t; cin >> t;
    while(t--){
        int a; ll n; cin >> a >> n; ll m=sqrt(a*n);
        while((m+1)*(m+1)<=a*n) m++;
        while(m*m>a*n) m--;
        ll tot=mul(mul(m,m+1),mul(2*m+1,Pow(6)));
        tot=sub(tot,m);
        for(int i=0; i<a; ++i){
            int x=(1ll*i*i+a-1)%a,cnt=m/a;
            if(i&&i<=m%a) cnt++;
            tot=sub(tot,mul(x,cnt));
        }
        tot=mul(tot,Pow(a));
        cout << sub(n%mod*m%mod,tot) << "\n";
    }
}
0