結果

問題 No.1918 Simple Math ?
ユーザー とりゐ
提出日時 2022-04-09 01:04:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 241 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 138,368 KB
最終ジャッジ日時 2024-06-29 02:09:13
合計ジャッジ時間 4,791 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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=m*(2*m*m+3*m-5)//6-c[a]*p-c[q]
  print((n*m-ans//a)%(10**9+7))
0