結果

問題 No.1918 Simple Math ?
ユーザー とりゐ
提出日時 2022-04-14 23:38:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 241 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 138,496 KB
最終ジャッジ日時 2024-06-29 02:09:19
合計ジャッジ時間 5,269 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
for _ in range(int(input())):
  a,n=map(int,input().split())
  m=math.isqrt(a*n)
  c=[0]*(a+1)
  for i in range(1,a+1):
    c[i]=c[i-1]+(i*i-1)%a
  p,q=m//a,m%a
  ans=n*m-(m*(2*m*m+3*m-5)//6-c[a]*p-c[q])//a
  print(ans%(10**9+7))
0