-
Notifications
You must be signed in to change notification settings - Fork 0
/
Amrstrong_number.py
84 lines (66 loc) · 1.78 KB
/
Amrstrong_number.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Program to check Armstrong numbers in certain interval
import time
lower = 100
upper = 2000000
from numba import jit
# To take input from the user
#lower = int(input("Enter lower range: "))
#upper = int(input("Enter upper range: "))
def time_it(func):
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args,**kwargs)
end = time.time()
print(func.__name__ +" took " + str((end-start)*1000) + " ms")
return result
return wrapper
"""
for num in range(lower, upper + 1):
# order of number
order = len(str(num))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
"""
@time_it
def Armstrong_list(lower,upper):
print("List of Armstrong number from ",lower," to ",upper)
for num in range(lower, upper + 1):
# order of number
order = len(str(num))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
@time_it
@jit(parallel=True)
def Armstrong_list_jit(lower,upper):
print("List of Armstrong number from ",lower," to ",upper)
for num in range(lower, upper + 1):
# order of number
order = len(str(num))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
Armstrong_list(lower,upper)
Armstrong_list_jit(lower,upper)