結果
問題 | No.577 Prime Powerful Numbers |
ユーザー | yuppe19 😺 |
提出日時 | 2017-10-15 23:56:11 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 956 ms / 2,000 ms |
コード長 | 1,548 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 76,964 KB |
実行使用メモリ | 102,268 KB |
最終ジャッジ日時 | 2024-04-28 22:11:40 |
合計ジャッジ時間 | 6,796 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 297 ms
100,608 KB |
testcase_01 | AC | 348 ms
100,124 KB |
testcase_02 | AC | 234 ms
97,920 KB |
testcase_03 | AC | 459 ms
102,216 KB |
testcase_04 | AC | 324 ms
100,224 KB |
testcase_05 | AC | 882 ms
101,160 KB |
testcase_06 | AC | 380 ms
101,368 KB |
testcase_07 | AC | 956 ms
102,268 KB |
testcase_08 | AC | 432 ms
101,600 KB |
testcase_09 | AC | 423 ms
100,740 KB |
testcase_10 | AC | 227 ms
97,792 KB |
ソースコード
#!/usr/bin/python2 # -*- coding: utf-8 -*- # † from collections import defaultdict, deque from fractions import gcd from random import randrange from fractions import Fraction as frac def is_probable_prime(n, k=20): if n < 2: return False for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]: if n < p * p: return True if n % p == 0: return False s, d = 0, n-1 while d & 1 == 0: s, d = s+1, d>>1 for _ in xrange(k): a = randrange(2, n-1) x = pow(a, d, n) if x == 1 or x == n-1: continue for _ in xrange(s-1): x = (x * x) % n if x == n-1: break # could be strong liar, try another a else: return False # composite if we reached end of this loop return True # probably prime if reached end of outer loop def g(pa, a): lo, hi = 1, int(pow(pa, frac(1, a))) + 2 while hi - lo > 1: md = (lo + hi) / 2 if md ** a <= pa: lo = md else: hi = md return lo def f(n): if n == 2: return False if n % 2 == 0: return True b = 2 while b < n: pa = n - b a = 1 mull = 3 while mull <= pa: p = g(pa, a) if p**a == pa and is_probable_prime(p): return True a += 1 mull *= 3 b *= 2 return False Q = int(raw_input()) for _ in xrange(Q): n = int(raw_input()) able = f(n) print 'Yes' if able else 'No'