UVa 10139
From Algorithmist
Contents |
[edit] 10139 - Factovisors
[edit] Summary
Summary of the problem statement goes here.
[edit] Explanation
- Simply any number can be represented as product of primes to powers:
-
So now only reprsent the second number (which will divide the factorial) and see if the powers of its prime less than the powers in the factorial.
For example assume we need to know if 12 divides 6! or not.
- Start for representing 12 as 12 = 22 * 31
Now call some function to tell you What is the power of a prime in factorial n;
now calling once for 2 we get that 6! has 24 Where 4 is great than 2 (22 < 24)
now calling once for 3 we get that 6! has 32 Where 2 is great than 1 (31 < 32)
After finishing all the powers of 12 without any problems 12 divides 6!
[edit] Gotchas
- Any points one can easily overlook?
- The correct way to understand ambiguous formulations?
[edit] Notes
- 0 divides n! is false.
- m divides n! is true if
[edit] Input
6 9 6 27 20 10000 20 100000 1000 1009
[edit] Output
9 divides 6! 27 does not divide 6! 10000 divides 20! 100000 does not divide 20! 1009 does not divide 1000!

