結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー googol_S0googol_S0
提出日時 2021-10-29 22:20:31
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 539 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 86,564 KB
実行使用メモリ 76,836 KB
最終ジャッジ日時 2023-07-29 08:15:54
合計ジャッジ時間 3,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,596 KB
testcase_01 AC 62 ms
71,724 KB
testcase_02 AC 68 ms
71,596 KB
testcase_03 AC 67 ms
71,696 KB
testcase_04 AC 68 ms
71,392 KB
testcase_05 AC 71 ms
75,560 KB
testcase_06 AC 69 ms
76,136 KB
testcase_07 AC 67 ms
75,764 KB
testcase_08 AC 72 ms
76,220 KB
testcase_09 AC 72 ms
75,544 KB
testcase_10 AC 77 ms
76,636 KB
testcase_11 AC 75 ms
75,824 KB
testcase_12 AC 73 ms
76,016 KB
testcase_13 AC 73 ms
75,996 KB
testcase_14 AC 71 ms
75,656 KB
testcase_15 AC 75 ms
75,744 KB
testcase_16 AC 75 ms
75,836 KB
testcase_17 AC 70 ms
76,448 KB
testcase_18 AC 74 ms
76,508 KB
testcase_19 AC 72 ms
75,840 KB
testcase_20 AC 73 ms
76,464 KB
testcase_21 AC 72 ms
75,996 KB
testcase_22 AC 74 ms
76,364 KB
testcase_23 AC 265 ms
76,836 KB
testcase_24 AC 199 ms
76,684 KB
testcase_25 AC 72 ms
75,608 KB
testcase_26 AC 73 ms
75,900 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