結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
![]() |
提出日時 | 2021-03-16 15:55:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 209 ms / 2,000 ms |
コード長 | 2,173 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 12,032 KB |
最終ジャッジ日時 | 2024-11-08 01:46:07 |
合計ジャッジ時間 | 1,936 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 class Sieve: def __init__(self, n): self.plist = [2] # n以下の素数のリスト min_prime_factor = [2, 0] * (n // 2 + 5) for x in range(3, n + 1, 2): if min_prime_factor[x] == 0: min_prime_factor[x] = x self.plist.append(x) if x ** 2 > n: continue for y in range(x ** 2, n + 5, 2 * x): if min_prime_factor[y] == 0: min_prime_factor[y] = x self.min_prime_factor = min_prime_factor def isprime(self, x): return self.min_prime_factor[x] == x # これが素因数分解(prime factorization) def pfct(self, x): pp, ee = [], [] while x > 1: mpf = self.min_prime_factor[x] if pp and mpf == pp[-1]: ee[-1] += 1 else: pp.append(mpf) ee.append(1) x //= mpf return [(p, e) for p, e in zip(pp, ee)] n,k=LI() sv=Sieve(n) pe=sv.pfct(n) mn=1 cnt=k for p,e in pe: if cnt==0:break c=min(e,cnt) mn*=p**c cnt-=c from math import gcd def cnt_fac(a): pe=sv.pfct(a) cur=1 for p,e in pe:cur*=e+1 return cur def cnt_prifac(a): pe=sv.pfct(a) return sum(e for p,e in pe) ans=mx=-1 for a in range(mn,n): g=gcd(n,a) if g<mn:continue if cnt_prifac(g)<k:continue cur=cnt_fac(a) if cur>mx: mx=cur ans=a print(ans)