結果

問題 No.1918 Simple Math ?
ユーザー とりゐとりゐ
提出日時 2022-04-08 22:42:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 394 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 153,912 KB
最終ジャッジ日時 2023-09-11 11:32:16
合計ジャッジ時間 6,920 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
83,224 KB
testcase_01 AC 79 ms
75,508 KB
testcase_02 AC 79 ms
75,504 KB
testcase_03 AC 79 ms
75,480 KB
testcase_04 AC 79 ms
75,432 KB
testcase_05 AC 79 ms
75,436 KB
testcase_06 AC 101 ms
83,496 KB
testcase_07 AC 112 ms
87,560 KB
testcase_08 AC 94 ms
81,580 KB
testcase_09 AC 88 ms
78,552 KB
testcase_10 AC 105 ms
83,332 KB
testcase_11 AC 80 ms
76,056 KB
testcase_12 AC 107 ms
86,164 KB
testcase_13 AC 95 ms
82,344 KB
testcase_14 AC 90 ms
79,684 KB
testcase_15 AC 83 ms
77,116 KB
testcase_16 AC 176 ms
109,048 KB
testcase_17 AC 179 ms
111,852 KB
testcase_18 AC 214 ms
124,836 KB
testcase_19 AC 222 ms
128,300 KB
testcase_20 AC 197 ms
119,176 KB
testcase_21 AC 282 ms
150,312 KB
testcase_22 AC 277 ms
149,588 KB
testcase_23 AC 281 ms
149,356 KB
testcase_24 AC 279 ms
149,120 KB
testcase_25 AC 281 ms
149,756 KB
testcase_26 AC 289 ms
153,700 KB
testcase_27 AC 288 ms
153,776 KB
testcase_28 AC 205 ms
121,392 KB
testcase_29 AC 75 ms
71,420 KB
testcase_30 AC 73 ms
71,120 KB
testcase_31 AC 285 ms
153,912 KB
testcase_32 AC 78 ms
75,412 KB
testcase_33 AC 77 ms
75,432 KB
権限があれば一括ダウンロードができます

ソースコード

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