結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー vwxyzvwxyz
提出日時 2023-05-25 01:57:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,065 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 78,052 KB
最終ジャッジ日時 2023-08-25 15:51:27
合計ジャッジ時間 5,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,704 KB
testcase_01 AC 91 ms
71,588 KB
testcase_02 AC 91 ms
71,684 KB
testcase_03 AC 90 ms
71,720 KB
testcase_04 AC 90 ms
71,660 KB
testcase_05 AC 96 ms
76,964 KB
testcase_06 AC 97 ms
76,864 KB
testcase_07 AC 95 ms
76,920 KB
testcase_08 AC 103 ms
76,968 KB
testcase_09 AC 101 ms
76,704 KB
testcase_10 AC 103 ms
76,956 KB
testcase_11 AC 101 ms
76,852 KB
testcase_12 AC 103 ms
77,128 KB
testcase_13 AC 104 ms
76,980 KB
testcase_14 AC 102 ms
76,716 KB
testcase_15 AC 101 ms
76,796 KB
testcase_16 AC 104 ms
77,320 KB
testcase_17 AC 102 ms
76,920 KB
testcase_18 AC 101 ms
76,740 KB
testcase_19 AC 102 ms
76,796 KB
testcase_20 AC 102 ms
76,744 KB
testcase_21 AC 101 ms
76,984 KB
testcase_22 AC 103 ms
76,964 KB
testcase_23 AC 131 ms
77,784 KB
testcase_24 AC 129 ms
78,052 KB
testcase_25 AC 108 ms
76,856 KB
testcase_26 AC 100 ms
76,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
from collections import defaultdict

def Divisors(N):
    divisors=[]
    for i in range(1,N+1):
        if i**2>=N:
            break
        elif N%i==0:
            divisors.append(i)
    if i**2==N:
        divisors+=[i]+[N//i for i in divisors[::-1]]
    else:
        divisors+=[N//i for i in divisors[::-1]]
    return divisors

def Factorize(N):
    assert N>=1
    factors=defaultdict(int)
    for p in range(2,N):
        if p**2>N:
            break
        while N%p==0:
            factors[p]+=1
            N//=p
    if N!=1:
        factors[N]+=1
    return factors

T=int(readline())
mod=10**9+7
for t in range(T):
    N,C=map(int,readline().split())
    D=Divisors(N)
    fact=Factorize(N)
    cnt=defaultdict(int)
    for d in D:
        cnt[d]+=N//d
    for p in fact:
        for d in D:
            if d%p==0:
                cnt[d//p]-=cnt[d]
    ans=pow(C,N,mod)*N%mod
    for d,c in cnt.items():
        ans+=pow(C,d*2,mod)*c%mod
        ans%=mod
    ans*=pow(2*N,mod-2,mod)
    ans%=mod
    print(ans)
0