結果
問題 |
No.1322 Totient Bound
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:33:23 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,499 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,196 KB |
最終ジャッジ日時 | 2025-04-15 22:35:30 |
合計ジャッジ時間 | 16,287 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 TLE * 1 -- * 20 |
ソースコード
import sys sys.setrecursionlimit(1 << 25) def is_prime(n): if n < 2: return False for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]: if n % p == 0: return n == p d = n - 1 s = 0 while d % 2 == 0: d //= 2 s += 1 for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: if a >= n: continue x = pow(a, d, n) if x == 1 or x == n - 1: continue for _ in range(s - 1): x = pow(x, 2, n) if x == n - 1: break else: return False return True def count_valid_x(N): if N < 1: return 0 count = 0 def dfs(remaining, min_p): nonlocal count count += 1 # current x is valid p = min_p while True: current_p_minus_1 = p - 1 if current_p_minus_1 > remaining: break if is_prime(p): contribution = current_p_minus_1 e = 1 while True: if contribution > remaining: break new_remaining = remaining // contribution dfs(new_remaining, p + 1) contribution *= p e += 1 if contribution > remaining: break p += 1 dfs(N, 2) return count N = int(sys.stdin.readline()) print(count_valid_x(N))