結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー googol_S0googol_S0
提出日時 2021-10-29 22:20:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 539 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 71,936 KB
最終ジャッジ日時 2024-04-16 15:10:40
合計ジャッジ時間 2,822 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,480 KB
testcase_01 AC 43 ms
52,736 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 42 ms
52,608 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 46 ms
57,984 KB
testcase_06 AC 50 ms
58,880 KB
testcase_07 AC 45 ms
57,856 KB
testcase_08 AC 56 ms
59,008 KB
testcase_09 AC 50 ms
58,368 KB
testcase_10 AC 56 ms
60,928 KB
testcase_11 AC 52 ms
59,008 KB
testcase_12 AC 53 ms
59,392 KB
testcase_13 AC 54 ms
59,392 KB
testcase_14 AC 51 ms
58,752 KB
testcase_15 AC 54 ms
59,392 KB
testcase_16 AC 55 ms
59,904 KB
testcase_17 AC 52 ms
59,264 KB
testcase_18 AC 54 ms
60,288 KB
testcase_19 AC 54 ms
59,776 KB
testcase_20 AC 53 ms
60,160 KB
testcase_21 AC 53 ms
59,264 KB
testcase_22 AC 54 ms
59,136 KB
testcase_23 AC 269 ms
71,936 KB
testcase_24 AC 196 ms
70,784 KB
testcase_25 AC 49 ms
57,344 KB
testcase_26 AC 52 ms
59,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
mod=10**9+7
T=int(input())
def solve(N,C):
  ANS=pow(C,N,mod)*N%mod
  P=[]
  for i in range(1,int(N**0.5)+1):
    if N%i==0:
      P.append(i)
      if i*i!=N:
        P.append(N//i)
  P=sorted(set(P))
  L=len(P)
  X=[0]*L
  for i in range(L-1,-1,-1):
    X[i]=N//P[i]
    for j in range(i+1,L):
      if P[j]%P[i]==0:
        X[i]=X[i]-X[j]
  for i in range(L):
    x=pow(C,P[i],mod)
    ANS=(ANS+x*x*X[i])%mod
  return ANS*pow(N*2,mod-2,mod)%mod

for t in range(T):
  N,C=map(int,input().split())
  print(solve(N,C))
0