結果

問題 No.1727 [Cherry 3rd Tune] Stray
ユーザー googol_S0googol_S0
提出日時 2021-10-29 22:20:41
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 75 ms / 6,000 ms
コード長 539 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 72,128 KB
最終ジャッジ日時 2023-07-29 08:15:56
合計ジャッジ時間 1,617 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,724 KB
testcase_01 AC 70 ms
71,976 KB
testcase_02 AC 69 ms
71,740 KB
testcase_03 AC 75 ms
72,128 KB
testcase_04 AC 70 ms
71,672 KB
testcase_05 AC 72 ms
71,784 KB
testcase_06 AC 69 ms
71,784 KB
testcase_07 AC 73 ms
71,824 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