結果

問題 No.1918 Simple Math ?
ユーザー i_am_noob
提出日時 2023-02-11 03:10:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 194,792 KB
最終ジャッジ日時 2025-02-10 14:04:47
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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