10780 - Again Prime? No Time.
Moderator: Board moderators
Hi Suman:
Here is my algo, i hope you find it useful...
1. Find all the primes from 1..5000.
2. For each prime x that divides m find such a1 that m % x^a1 == 0 and a2 that n! % x^a2 == 0, if a1 > a2 then n! is not divided by m else store the minimal a2 / a1 and that is the result.
I Hope you solve that!!!
Here is my algo, i hope you find it useful...
1. Find all the primes from 1..5000.
2. For each prime x that divides m find such a1 that m % x^a1 == 0 and a2 that n! % x^a2 == 0, if a1 > a2 then n! is not divided by m else store the minimal a2 / a1 and that is the result.
![:D](./images/smilies/icon_biggrin.gif)
I Hope you solve that!!!
(correction: apparently you meant the greatest power of 13)minskcity wrote:I think this problem's description is WRONG!!!!
The smallest power of 13 that divides 2! does exist - it is 0.
![]()
![]()
![]()
![]()
![]()
No need to be angry, just read the problem statement more carefully. The problem description is correct, as is your (corrected) second sentence. Let's see some quotes:
This is the sentence you are referring to. Basically, this sentence tells you what to do.problem description wrote:Given a number n you have to determine the largest power of m, not necessarily prime, that divides n!.
This is the output description. After you have solved the problem, this section tells you how to format your output. In my humble opinion, the case "m doesn't divide n!" is exactly the case when the greatest power of m dividing n! is 0. So, this section tells you: instead of zero, output a message. What's wrong with that?output description wrote:The result is either an integer if m divides n! or a line "Impossible to divide" (without the quotes).
For many problems from Valladolid the second option (such as "no solution") never needs to be printed. How do I know that it's not the case here? It is quite clear to me that division is always possible according to problem statement...misof wrote:This is the output description. After you have solved the problem, this section tells you how to format your output. In my humble opinion, the case "m doesn't divide n!" is exactly the case when the greatest power of m dividing n! is 0. So, this section tells you: instead of zero, output a message. What's wrong with that?output description wrote:The result is either an integer if m divides n! or a line "Impossible to divide" (without the quotes).
![:roll:](./images/smilies/icon_rolleyes.gif)
Why exactly am I supposed to print "Impossible to divide" when I can divide by 23^0? Can you give me the sentence in problem statement that says so? My understanding of "impossible to divide" is impossible to divide and not "impossible to divide for the exception of M^0". I see nothing that makes zero special in the problem statement. And if I have to print "impossible to divide" when answer is 0, why should not I print "impossible to divide" when answer is 1, 2, 3....????
![:roll:](./images/smilies/icon_rolleyes.gif)
![:-?](./images/smilies/icon_confused.gif)
![:roll:](./images/smilies/icon_rolleyes.gif)
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
I have a problem with this problem ![;)](./images/smilies/icon_wink.gif)
My algorithm is:
1. generate primes in range [2...5000]
2. for each M,N pair
- factorize M using prime table from step 1
- factorize N! using prime table from step 1
- output (power of max prime in M in N!)/(power of max prime in M) if it's greater than 0 or appropriate message
Is this wrong ?
I check all I/O posted, but in all cases I got correct answer. Could anyone help me ?
Best regards
DM
![;)](./images/smilies/icon_wink.gif)
My algorithm is:
1. generate primes in range [2...5000]
2. for each M,N pair
- factorize M using prime table from step 1
- factorize N! using prime table from step 1
- output (power of max prime in M in N!)/(power of max prime in M) if it's greater than 0 or appropriate message
Is this wrong ?
I check all I/O posted, but in all cases I got correct answer. Could anyone help me ?
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
Only consideringing the max prime factor in M is not enough. Consider cases such as:Dominik Michniewski wrote:My algorithm is:
1. generate primes in range [2...5000]
2. for each M,N pair
- factorize M using prime table from step 1
- factorize N! using prime table from step 1
- output (power of max prime in M in N!)/(power of max prime in M) if it's greater than 0 or appropriate message
Is this wrong ?
Code: Select all
2
12 3
96 96
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- New poster
- Posts: 13
- Joined: Sun Aug 28, 2005 3:39 pm
- Location: Taiwan
10780 WA plz help!!!!!
I tried all the input posted in former topics and all he output is right.
BUT I still got WA!!!!!Why?
Can someone tell me what's wrong in my code?
Thanks!!!!!!
BUT I still got WA!!!!!Why?
![:(](./images/smilies/icon_frown.gif)
Can someone tell me what's wrong in my code?
Thanks!!!!!!
Code: Select all
removed after AC
Last edited by georgemouse on Tue Jan 31, 2006 4:07 pm, edited 1 time in total.
-
- New poster
- Posts: 13
- Joined: Sun Aug 28, 2005 3:39 pm
- Location: Taiwan
The way I used is to find the largest prime factor in M (the largest prime factor is K)
then find the largest power of M that divides N:
if K^a divides N!,
then I'll find the largest 'b' that k^b divides M.
At last, I'll output a/b (if it's 0 , output "Impossible to divide").
example:
if N=11,M=8=2^3
8's largest prime factor is 2
11/2->5
5/2->2
2/2->1
a=5+2+1=8
b=3
8/3=2
output 2
then find the largest power of M that divides N:
if K^a divides N!,
then I'll find the largest 'b' that k^b divides M.
At last, I'll output a/b (if it's 0 , output "Impossible to divide").
example:
if N=11,M=8=2^3
8's largest prime factor is 2
11/2->5
5/2->2
2/2->1
a=5+2+1=8
b=3
8/3=2
output 2
Last edited by georgemouse on Mon Sep 12, 2005 7:21 am, edited 1 time in total.