LoginSignup
0
0

More than 1 year has passed since last update.

【Project Euler】Problem 29: べき乗の値

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

問題 29:べき乗の値

原文 Problem 29: Distinct powers

問題の要約:$2 \leq a, b \leq 100$ のとき$a^b$の値の数を求めよ、ただし重複はかぞえない

Pythonでは2重ループはitertools、重複を除くのはsetを使うと簡潔に書けますね。

from itertools import product
ab = range(2, 100+1)
print(f"Answer : {len(set([a**b for a, b in product(ab,repeat=2)]))}")

(開発環境:Google Colab)

0
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
0
0