結果
問題 | No.2795 Perfect Number |
ユーザー | june19312 |
提出日時 | 2024-06-28 22:54:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 2,706 bytes |
コンパイル時間 | 125 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 76,144 KB |
最終ジャッジ日時 | 2024-06-28 22:55:00 |
合計ジャッジ時間 | 2,686 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
53,028 KB |
testcase_01 | AC | 33 ms
52,528 KB |
testcase_02 | AC | 36 ms
53,132 KB |
testcase_03 | AC | 35 ms
53,548 KB |
testcase_04 | AC | 34 ms
53,852 KB |
testcase_05 | AC | 34 ms
54,948 KB |
testcase_06 | AC | 33 ms
53,252 KB |
testcase_07 | AC | 33 ms
53,960 KB |
testcase_08 | AC | 34 ms
53,352 KB |
testcase_09 | AC | 32 ms
53,588 KB |
testcase_10 | AC | 35 ms
53,436 KB |
testcase_11 | AC | 33 ms
54,168 KB |
testcase_12 | AC | 33 ms
53,956 KB |
testcase_13 | AC | 37 ms
53,968 KB |
testcase_14 | AC | 79 ms
75,796 KB |
testcase_15 | AC | 81 ms
76,144 KB |
testcase_16 | AC | 82 ms
76,116 KB |
testcase_17 | AC | 80 ms
75,912 KB |
testcase_18 | AC | 84 ms
75,860 KB |
testcase_19 | AC | 35 ms
53,164 KB |
testcase_20 | AC | 36 ms
53,328 KB |
testcase_21 | AC | 37 ms
53,356 KB |
testcase_22 | AC | 34 ms
54,204 KB |
testcase_23 | AC | 36 ms
53,440 KB |
testcase_24 | AC | 36 ms
53,536 KB |
testcase_25 | AC | 36 ms
54,296 KB |
testcase_26 | AC | 40 ms
53,824 KB |
testcase_27 | AC | 39 ms
60,776 KB |
testcase_28 | AC | 47 ms
64,996 KB |
testcase_29 | AC | 38 ms
53,256 KB |
testcase_30 | AC | 35 ms
53,820 KB |
testcase_31 | AC | 34 ms
54,300 KB |
testcase_32 | AC | 34 ms
52,744 KB |
testcase_33 | AC | 34 ms
53,704 KB |
testcase_34 | AC | 33 ms
52,880 KB |
testcase_35 | AC | 44 ms
60,772 KB |
testcase_36 | AC | 37 ms
53,148 KB |
testcase_37 | AC | 35 ms
54,216 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) import pypyjit pypyjit.set_param('max_unroll_recursion=-1') def gcd(a, b): while b: a, b = b, a % b return a def isPrimeMR(n): assert 0 < n < 2**64 if n == 1: return 0 d = n - 1 d = d // (d & -d) L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] for a in L: if n == a: return 1 t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def bunkai(x): bunkaians = [] for bunkaiind,bunkaival in x.items(): for j in range(bunkaival): bunkaians.append(bunkaiind) return bunkaians def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2 ** 20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret N = int(input()) tmp = primeFactor(N) tmp1,tmp2 = [],[] for ind,val in tmp.items(): tmp1.append(ind) tmp2.append(val) ans = 0 def check(x): tmpans = 1 for j in range(len(x)): tmpans *= tmp1[j] ** x[j] global ans ans += tmpans return def dfs(x,y): if len(x) == len(tmp1): check(x) return for i in range(tmp2[y]+1): x.append(i) dfs(x,y+1) x.pop() dfs([],0) if N*2 == ans: print("Yes") else: print("No")