All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Factorial Crossed Nonzero Digits Determination (Posted on 2022-12-01) Difficulty: 3 of 5
Without actual evaluation, determine the last 3 nonzero digits of:
            33! - 23!

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Solution | Comment 1 of 4
33! will have way more zeros at the end than 23!, surely more than 3 more.
How many more zeros are there at the end of 33! vs 23!?  Factors contributing a "5" would include 25 (2 fives) and 30 (1 five).  So 33! has 3 more zeros than 23!

So we need only find the last 3 nonzero digits of 23! and then subtract that from 1000.
Begin by making a list of prime factors of each number from 2 to 23, 
then delete any factors of 10 (of which there are none since 10 is not prime), 
then delete equal numbers of 2's and 5's
then sequentially multiply the next prime factor by the running product mod 1000.
finally subtract the final product mod 1000 from 1000.


336 is the output of the following code
-----------------------------
def prime_factor(n): 
    """  for integer n, return a list of all the prime factors """
    top = n // 2
    factors = []
    
    for i in range(2,top+1):
        while n/i % 1 == 0:
            factors.append(int(i))
            n = n/i
            if n == 1:
                return factors
    if n != 1:
        factors.append(int(n))
    return factors

def countem(aList, value):
    """ return the number of instances of value in aList  """
    ans = 0
    for val in aList:
        if val == value:
            ans += 1
    return ans

def last3digits(n):
    """ output the last 3 nonzero digits of n!  """
    listOfFactors = []
    for i in range(2,23+1):
        for p in prime_factor(i):
            listOfFactors.append(p)
    listOfFactors = sorted(listOfFactors)
    twos = countem(listOfFactors,2)
    fives = countem(listOfFactors,5)
    toBeDeleted = min(twos, fives)
    for k in range(toBeDeleted):
        listOfFactors.remove(2)
        listOfFactors.remove(5)
    truncatedProduct = 1
    for f in listOfFactors:
        truncatedProduct = (truncatedProduct*f)%1000
    return truncatedProduct

print(1000 - last3digits(23))

  Posted by Larry on 2022-12-01 07:36:07
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (15)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information