1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Project Euler】Problem 47: 素因数の個数

Last updated at Posted at 2022-01-22
  • 本記事はProjectEulerの「100番以下の問題の説明は記載可能」という規定に基づいて回答のヒントが書かれていますので、自分である程度考えてみてから読まれることをお勧めします。

問題 47. 素因数の個数

原文 Problem 47: Distinct primes factors

問題の要約:正の整数の異なる素因数が4個になる数が初めて4つ連続する最初の数を求めよ

異なる素因数の数はsympyfactorintの返すDICT型の長さを見れば分かります。

import itertools
from sympy import factorint

ccnt = 0
for n in itertools.count(1):
  ccnt = ccnt+1 if len(factorint(n))==4 else 0
  if ccnt >= 4:
      break

print(f"Answer: {n-3}")
for i in range(n-3,n+1):
   print(i, factorint(i))

(開発環境:Google Colab)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?