0
3

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 5 years have passed since last update.

Pythonの演習問題

Last updated at Posted at 2016-12-05

問題

 ある$n$桁の自然数$m$、1桁目の数字は$a_1$と、2桁目の数字は$a_2$と、...$n$桁目の数字は$a_n$とします。次の条件が満たされる$m$をすべて見つけなさい。
$$m=a_1^n+\cdots+a_n^n$$

答え

桁数$n$は2から7まで取って計算してみました。

n=2

n=3
153 370 371 407 
n=4
1634 8208 9474 
n=5
54748 92727 93084 
n=6
548834 
n=7
1741725 4210818 9800817 9926315  
code.py
for n in range(2,8):
    print("\nn=%d"%n)
    for i in range(10**(n-1), 10**n):
        x = sum((i // 10**j % 10)**n for j in range(n))
        if(x == i):
            print("%d "%i,end="")
0
3
2

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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?