-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
47 lines (39 loc) · 846 Bytes
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Check if fibonacci or not
# def fibonacci(n):
# prev , curr = 0, 1
# while curr < n:
# temp = prev + curr
# prev = curr
# curr = temp
# if (curr == n):
# return True
# else:
# return False
# n = int(input())
# print(fibonacci(n))
# Check Armstrong
"""
An Armstrong number is a number (with digits n)
such that the sum of its digits raised to nth power is equal to the number itself.
For example,
371, as 3^3 + 7^3 + 1^3 = 371
1634, as 1^4 + 6^4 + 3^4 + 4^4 = 1634
"""
def armstrong(n):
m = n
digits = ans = 0
while m:
m //= 10
digits += 1
m = n
while m:
a = m % 10
m //= 10
ans += (a**digits)
# print(ans)
if ans == n:
return True
else:
return False
n = int(input())
print(armstrong(n))