結果

問題 No.1918 Simple Math ?
ユーザー kozykozy
提出日時 2022-04-30 00:53:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 909 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 116,584 KB
最終ジャッジ日時 2023-09-11 16:43:49
合計ジャッジ時間 10,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 772 ms
84,968 KB
testcase_01 AC 141 ms
78,192 KB
testcase_02 AC 126 ms
77,844 KB
testcase_03 AC 163 ms
78,680 KB
testcase_04 AC 147 ms
77,716 KB
testcase_05 AC 154 ms
78,300 KB
testcase_06 AC 288 ms
78,620 KB
testcase_07 AC 276 ms
79,160 KB
testcase_08 AC 163 ms
77,996 KB
testcase_09 AC 213 ms
78,492 KB
testcase_10 AC 502 ms
82,536 KB
testcase_11 AC 154 ms
78,068 KB
testcase_12 AC 666 ms
84,052 KB
testcase_13 AC 728 ms
84,640 KB
testcase_14 AC 131 ms
77,736 KB
testcase_15 AC 195 ms
79,096 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
  K=[0]*a
  for i in range(a,4*a):
    s=f(i*a)
    K[s-a]+=1
  x=f(N//a)
  #x>=1
  s1=0
  s2=0
  s3=3*a
  kosu=a
  for i in range(a):
    s1+=(i+a)*K[i]%mod
    s2+=(i+a)
    s1%=mod
    s2%=mod
  if x>=2:
    ans+=s1*(x-1)%mod
    ans+=(a*kosu%mod*((x-2)*(x-1)*(2*x-3))//3)%mod
    ans+=(((x-2)*(x-1))//2)*a%mod*s3%mod
    ans+=(x-2)*(x-1)*s2%mod
    ans%=mod
  #(x**2)*a~N
  kk=N-((x**2)*a)+1
  for i in range(a):
    if kk-(K[i]+2*(x-1))<=0:
      ans+=kk*(i+a*x)
      ans%=mod
      break
    else:
      kk-=(K[i]+2*(x-1))
      kk%=mod
      ans+=(i+a*x)*(K[i]+2*(x-1))%mod
      ans%=mod
  print(ans)
0