結果

問題 No.1918 Simple Math ?
ユーザー kozykozy
提出日時 2022-04-29 23:16:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 978 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 268,468 KB
最終ジャッジ日時 2023-09-11 14:47:45
合計ジャッジ時間 16,552 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,868 ms
258,432 KB
testcase_01 AC 168 ms
79,072 KB
testcase_02 AC 149 ms
78,376 KB
testcase_03 AC 194 ms
79,788 KB
testcase_04 AC 174 ms
78,972 KB
testcase_05 AC 193 ms
79,080 KB
testcase_06 AC 386 ms
87,420 KB
testcase_07 AC 501 ms
102,592 KB
testcase_08 AC 272 ms
88,324 KB
testcase_09 AC 390 ms
95,764 KB
testcase_10 AC 1,130 ms
162,492 KB
testcase_11 AC 253 ms
89,148 KB
testcase_12 AC 1,577 ms
213,660 KB
testcase_13 AC 1,706 ms
237,048 KB
testcase_14 AC 171 ms
79,412 KB
testcase_15 AC 331 ms
91,768 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n):
  a=int(n**0.5)
  for i in range(-3,3):
    if (a+i)**2<=n<(a+i+1)**2:
      return a+i
T=int(input())
mod=10**9+7
for _ in range(T):
  a,N=map(int,input().split())
  ans=0
  for i in range(1,a):
    if i>N:
      break
    ans+=f(a*i)
    ans%=mod
  if a-1>=N:
    print(ans)
    continue
  d=dict()
  for i in range(a,4*a):
    if f(i*a) not in d:
      d[f(i*a)]=0
    d[f(i*a)]+=1
  x=f(N//a)
  #x>=1
  s1=0
  s2=0
  s3=0
  kosu=0
  for i in d:
    s1+=i*d[i]%mod
    s2+=i
    s3+=d[i]
    kosu+=1
    s1%=mod
    s2%=mod
    s3%=mod
  if x>=2:
    ans+=s1*(x-1)%mod
    ans+=(2*a*kosu%mod*((x-2)*(x-1)*(2*x-3))//6)%mod
    ans+=(((x-2)*(x-1))//2)*a%mod*s3%mod
    ans+=(((x-2)*(x-1))//2)*2*s2%mod
    ans%=mod
  #(x**2)*a~N
  kk=N-((x**2)*a)+1
  for i in d:
    if kk-(d[i]+2*(x-1))<=0:
      ans+=kk*(i+a*(x-1))%mod
      ans%=mod
      break
    else:
      kk-=(d[i]+2*(x-1))
      kk%=mod
      ans+=(i+a*(x-1))*(d[i]+2*(x-1))%mod
      ans%=mod
  print(ans)
0