結果
問題 | No.713 素数の和 |
ユーザー |
|
提出日時 | 2023-01-28 11:13:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,784 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 61,824 KB |
最終ジャッジ日時 | 2024-06-28 16:03:06 |
合計ジャッジ時間 | 1,149 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
import sysif sys.platform =='ios':import clipboarda=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.stdinni = 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 gcddef isprime(n):if n <= 2:return n == 2if n % 2 == 0:return Falses = 0t = n - 1while t % 2 == 0:s += 1t //= 2for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 31, 37]:if a >= n:breakx = pow(a, t, n)if x == 1 or x == n - 1:continuefor _ in range(s):x = (x * x) % nif x == n - 1:breakif x == n - 1:continuereturn Falsereturn Truedef Pollad(N):if N % 2 == 0:return 2if isprime(N):return Ndef f(x):return (x * x + 1) % Nstep = 0while True:step += 1x = stepy = f(x)while True:p = gcd(y - x + N, N)if p == 0 or p == N:breakif p != 1:return px = 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:continuep = Pollad(now)if p == now:ret.append(p)#else:#q.append(p)#q.append(now // p)return retN = ni()print(sum(Primefact(N)))