結果

問題 No.3505 Sum of Prod of Root
コンテスト
ユーザー Kurao
提出日時 2026-04-18 10:36:48
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,858 ms / 2,000 ms
コード長 2,817 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 360 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 295,676 KB
最終ジャッジ日時 2026-04-18 10:37:09
合計ジャッジ時間 20,799 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#--------------------------------------------------
import sys
import functools
#sys.setrecursionlimit(10**9)
#codon↓--------------------------------------------
_factorial=[1]
def factorial(n):
    while len(_factorial)<=n:
        _factorial.append((_factorial[-1]*len(_factorial))%mod)
    return _factorial[n]

def binom(n,r):
    if r>=mod:
        raise ValueError("r is too big")
    if n<0:
        return 0
    if r>n:
        return 0
    if r<0:
        return 0
    ans=((factorial(n)*pow(factorial(r),mod-2,mod))%mod*pow(factorial(n-r),mod-2,mod))%mod
    return ans

import string
import itertools
alp_low=list(string.ascii_lowercase)
alp_up=list(string.ascii_uppercase)
dij=[[0,1],[1,0],[0,-1],[-1,0]]

mod=998244353
INF=10**18
def dijkstra(edges, num_node,start):
    """

    [node_num,weight>0][
    
    (example)

    Edges = [
        [[1, 4], [2, 3]],
        [[0, 1], [3, 1]],
        [[3, 2]],
        [],
    ]
    """
    import heapq;n=[INF]*num_node;n[start]=0;n_name=[];heapq.heappush(n_name,[0,start])
    while len(n_name):
        _,min_p=heapq.heappop(n_name)
        for f in edges[min_p]:
            g,c=f
            if n[min_p]+c<n[g]:n[g]=n[min_p]+c;heapq.heappush(n_name,[n[min_p]+c,g])
    return n

def nin():
    return list(map(int,input().split()))
def deq(x):
    return [i-1 for i in x]
def pop_cnt(n):
    ans=0
    while n:
        if n%2:
            ans+=1
        n//=2
    return ans

import collections
def main():
    hen={}
    for i in range(2,10**6+10):
        now=i**3
        while now<=10**18+10**13:
            if now not in hen:
                hen[now]=1
            hen[now]*=i*pow(i-1,-1,mod)
            hen[now]%=mod
            now*=i
    hen=[(i,hen[i]) for i in hen]
    hen.sort()
    hen.reverse()
    #cophen=hen[:]
    def solve(n):
        #hen=cophen[:]
        def solve12(n):
            if round(n**0.5)**2==n:
                x=round(n**0.5)-1
                return (4*x*(x+1)*(2*x+1)*(3*x**2+3*x-1)+45*x**2*(x+1)**2+10*x*(x+1)*(2*x+1))//60+(x+1)**3
            now=max(0,int(n**0.5)-3)
            while (now+1)**2<n:
                now+=1
            x=now-1
            temp=(4*x*(x+1)*(2*x+1)*(3*x**2+3*x-1)+45*x**2*(x+1)**2+10*x*(x+1)*(2*x+1))//60
            while (now+1)**2<=n:
                now+=1
            return (n-now**2+1)*(n+now**2)//2*now+temp
        now=1
        ans=0
        kei=1
        while len(hen):
            if hen[-1][0]>n:
                ans+=(solve12(n)-solve12(now-1))*kei
                ans%=mod
                return ans
            else:
                ans+=(solve12(hen[-1][0]-1)-solve12(now-1))*kei
                now,dif=hen.pop(-1)
                kei*=dif
                kei%=mod
        return ans

    n,=nin()
    print(solve(n))
    
    
if __name__=="__main__":
    main()
0