結果

問題 No.1918 Simple Math ?
ユーザー kozykozy
提出日時 2022-04-29 23:32:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 941 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 286,260 KB
最終ジャッジ日時 2023-09-11 15:09:45
合計ジャッジ時間 11,205 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,052 ms
259,932 KB
testcase_01 AC 144 ms
79,016 KB
testcase_02 AC 125 ms
78,444 KB
testcase_03 AC 168 ms
78,904 KB
testcase_04 AC 147 ms
79,348 KB
testcase_05 AC 158 ms
79,252 KB
testcase_06 AC 294 ms
85,736 KB
testcase_07 AC 324 ms
97,616 KB
testcase_08 AC 175 ms
85,416 KB
testcase_09 AC 242 ms
90,968 KB
testcase_10 AC 645 ms
149,520 KB
testcase_11 AC 160 ms
85,920 KB
testcase_12 AC 834 ms
204,104 KB
testcase_13 AC 988 ms
228,364 KB
testcase_14 AC 133 ms
79,416 KB
testcase_15 AC 221 ms
88,304 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):
    s=f(i*a)
    if s not in d:
      d[s]=0
    d[s]+=1
  x=f(N//a)
  #x>=1
  s1=0
  s2=0
  s3=3*a
  kosu=a
  for i in d:
    s1+=i*d[i]%mod
    s2+=i
    s1%=mod
    s2%=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