We divide

What is the largest power of 3 3 that divides 567948952 ! 567948952!


The answer is 283974468.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Eamon Gupta
Aug 14, 2015

This is my code in Python 2.7:

1
2
3
4
5
6
7
8
a = 567948952
p = 1                       #starts with 3^1
ans=0
while 3**p<a:          # if 3^p < a then it carries on in the loop
    b = a/(3**p)       # This finds the floor of a divided by every power of 3 less than a
    ans = b+ans        # This sums all of the floors
    p+=1          # p is incremented by 1 and retested if 3^p is still less than a 
print ans     # when 3^p is more than a, the loop stops and prints the sum of the floors

This gives the output:

1
>>>283974468

Moderator note:

Why does this work? What are you counting?

Note: In CS, explaining why your code does what you claim it does, is important. You should be able to explain the underlying structure of your code in a clean, concise way.

I've edited it now so I've explained each line with a comment.

Eamon Gupta - 5 years, 10 months ago
Arulx Z
Aug 14, 2015

PHP solution -

1
2
3
4
$count = 0;
for ($i = 1; $i < 19; $i++)
    $count += floor(567948952 / pow(3, $i));
echo $count;

Yes I'm learning PHP :)

This is exactly similar to counting trailing zeroes . Here is a general formula to calculate largest power of x x in n ! n! :

i = 1 n n x i \huge{\sum _{ i=1 }^{ n }{ \left\lfloor \frac { n }{ { x }^{ i } } \right\rfloor }}

Note: you don't actually need to calculate upto n n

Moderator note:

Simple standard approach.

Ryan Tamburrino
Jul 27, 2015

Largest power α \alpha of a prime p p in n ! n! is calculated by α = n s p ( n ) p 1 \alpha = \dfrac{n-s_p(n)}{p-1} where s p ( n ) s_p(n) is the sum of the digits of n n when written in base p p . This can easily be proved by using the formula for the sum of a finite geometric series.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...