結果

問題 No.713 素数の和
ユーザー ch1channnch1channn
提出日時 2023-01-28 11:13:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 76,044 KB
最終ジャッジ日時 2023-09-11 01:32:04
合計ジャッジ時間 1,983 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,780 KB
testcase_01 AC 74 ms
71,296 KB
testcase_02 AC 77 ms
71,136 KB
testcase_03 AC 80 ms
76,044 KB
testcase_04 AC 86 ms
75,604 KB
testcase_05 AC 76 ms
71,716 KB
testcase_06 AC 74 ms
71,400 KB
testcase_07 AC 75 ms
71,404 KB
testcase_08 AC 77 ms
71,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
if sys.platform =='ios':
	import clipboard
	a=clipboard.get()
	a = a.split('\n')
	text = '\n'.join(a)
	with open('input_file.txt','w') as f:
		f.write(text)
	sys.stdin = open('input_file.txt')
sys.setrecursionlimit(4100000)
stdin = sys.stdin 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()
nm = lambda: map(int,input().split())

from math import gcd
def isprime(n):
    if n <= 2:
        return n == 2
    if n % 2 == 0:
        return False
    s = 0
    t = n - 1
    while t % 2 == 0:
        s += 1
        t //= 2
    
    for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 31, 37]:
        if a >= n:
            break
        x = pow(a, t, n)
        if x == 1 or x == n - 1:
            continue
        for _ in range(s):
            x = (x * x) % n
            if x == n - 1:
                break
        if x == n - 1:
            continue

        return False
    return True

def Pollad(N):
    if N % 2 == 0:
        return 2
    if isprime(N):
        return N
    def f(x):
        return (x * x + 1) % N
    step = 0

    while True:
        step += 1
        x = step
        y = f(x)
        while True:
            p = gcd(y - x + N, N)
            if p == 0 or p == N:
                break
            if p != 1:
                return p
            x = f(x)
            y = f(f(y))


def Primefact(N):
    if N == 1:
        return []
    q = [i for i in range(2,N+1)]
    #q.append(i)
    ret = []
    while q:
        now = q.pop()
        if now == 1:
            continue
        p = Pollad(now)
        if p == now:
            ret.append(p)
        #else:
            #q.append(p)
            #q.append(now // p)

    return ret
    
    
    
    
N = ni()
print(sum(Primefact(N)))
0