Last 3 non zero digits of factorial 100 in python/jupyter notebook

Viewed 20

I am trying to find the last 3 non-zero digits of factorial 100 and I am struggling to come up with the code for it. I have found answers for the last non-zero, but nothing involving the last few digits (and when I did find it, it was in java and not python).

1 Answers

from what I understand, you want to get the last 3 digit that are not 0, implying that if a digit is 0 you skip it and try to find one more

We're lacking about information about how you want to store them, but essentially what you want to do is start from the end, have a counter counting how many not 0 digit you've found, and add them to a list or something

You provided no code, but it would look something alike :

factorial= str(factorial_func(100)) # the value of your factorial

list_of_number = [] # list to store the value, could be anything
cpt = 0
index = 1
while cpt < 3 : # means we found 3 digit that are not 0
 if factorial[-index] != "0" :
     list_of_number.append(factorial[-index]) # factorial[-index] means checking the index element starting from the end, so first check last element (-1), then the one before (-2) until we found 3 none 0 digit
     cpt+=1 # +1 because we found one
     index+=1 # go to next index
 else:
     index+=1 
 
 
  
Related