結果

問題 No.1529 Constant Lcm
ユーザー shakayamishakayami
提出日時 2021-06-04 20:19:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 3,000 ms
コード長 1,244 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 91,344 KB
最終ジャッジ日時 2023-08-12 09:10:01
合計ジャッジ時間 5,465 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
73,112 KB
testcase_01 AC 120 ms
77,344 KB
testcase_02 AC 114 ms
73,324 KB
testcase_03 AC 114 ms
73,324 KB
testcase_04 AC 114 ms
73,312 KB
testcase_05 AC 115 ms
73,148 KB
testcase_06 AC 114 ms
73,596 KB
testcase_07 AC 115 ms
73,536 KB
testcase_08 AC 116 ms
73,488 KB
testcase_09 AC 116 ms
73,700 KB
testcase_10 AC 172 ms
89,900 KB
testcase_11 AC 141 ms
82,628 KB
testcase_12 AC 125 ms
78,944 KB
testcase_13 AC 160 ms
88,108 KB
testcase_14 AC 148 ms
84,880 KB
testcase_15 AC 149 ms
84,772 KB
testcase_16 AC 141 ms
83,436 KB
testcase_17 AC 136 ms
80,820 KB
testcase_18 AC 136 ms
80,960 KB
testcase_19 AC 148 ms
84,428 KB
testcase_20 AC 170 ms
90,908 KB
testcase_21 AC 174 ms
91,168 KB
testcase_22 AC 178 ms
91,344 KB
testcase_23 AC 174 ms
91,224 KB
testcase_24 AC 173 ms
90,652 KB
testcase_25 AC 178 ms
91,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
mod=998244353
import random
#N=int(input())
def solve(N):
    isPrime=[True for i in range(N+1)]
    isPrime[0]=False;isPrime[1]=False
    Prime=[]
    for i in range(2,N+1):
        if isPrime[i]:
            for j in range(2*i,N+1,i):
                isPrime[j]=False
            Prime.append(i)
    def primefact(M):
        res=defaultdict(int)
        p=2
        while(p*p<=M):
            while(M%p==0):
                res[p]+=1
                M//=p
            p+=1
        if M>1:res[M]+=1
        return res
    PF=primefact(N)
    ans=1
    for p in Prime:
        if N%p==0:
            continue
        k=0
        while(p**(k+1)<N):k+=1
        ans*=pow(p,k,mod)
        ans%=mod
    for p in PF:
        A=N//(p**PF[p])
        if A>1:
            cnt=PF[p]*2
            pr=p
            while(A>pr):
                cnt+=1
                pr*=p
            ans*=pow(p,cnt,mod)
            ans%=mod
        else:
            cnt=(PF[p]-1)*2
            ans*=pow(p,cnt,mod)
            ans%=mod
    return ans

from math import gcd
def lcm(x,y):return (x*y)//gcd(x,y)
def naive(N):
    L=1
    for i in range(1,N):
        L=lcm(L,i*(N-i))
    L%=mod
    return L
print(solve(int(input())))
0