結果

問題 No.1529 Constant Lcm
ユーザー shakayami
提出日時 2021-06-04 20:19:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 3,000 ms
コード長 1,244 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 83,972 KB
最終ジャッジ日時 2024-11-19 08:40:22
合計ジャッジ時間 3,045 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

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