Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@yopya

Project Euler 63「べき乗の桁の個数」

More than 3 years have passed since last update.

Problem 63 「べき乗の桁の個数」

5桁の数 16807 = 7^5は自然数を5乗した数である. 同様に9桁の数 134217728 = 8^9も自然数を9乗した数である.
自然数を n 乗して得られる n 桁の正整数は何個あるか?

def hoge():
    cnt = 0
    # 10**1=10(2桁)、10**2=100(3桁)、... なので10以上の数字のn乗がn桁になることはない
    for m in range(1, 10):
        n = 1
        while 1:
            if len(str(m ** n)) == n:
                cnt += 1
            else: # これでいいのかちょっと疑問
                break
            n += 1
    return cnt

print(hoge())
1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
yopya
自然に囲まれた田舎で働きたい。 田舎でPythonの仕事ないっすか?

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?