結果

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

ソースコード

diff #

def floor_sqrt(n):
  ng,ok=n+1,-1
  while ng-ok>1:
    mid=(ok+ng)//2
    if mid*mid<=n:
      ok=mid
    else:
      ng=mid
  return ok

def solve():
  a,n=map(int,input().split())
  m=floor_sqrt(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))

for _ in range(int(input())):
  solve()
0