Skip to content

improved the code by reducing the amount of time to calculate factorial from 0-9 #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions strong.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
sum1=0
num=int(input("Enter a number:"))
temp=num
while(num):
i=1
f=1
r=num%10
while(i<=r):
f=f*i
i=i+1
sum1=sum1+f
num=num//10
if(sum1==temp):
factorials = [1] * 10
for i in range(2, 10):
factorials[i] = factorials[i-1] * i
sum1 = 0
num = int(input("Enter a number:"))
temp = num
while num:
r = num % 10
sum1 += factorials[r]
num //= 10
if sum1 == temp:
print("The number is a strong number")
else:
print("The number is not a strong number")
print("The number is not a strong number")