Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Problem :
Now you have to solve an interesting problem. Any integer n (where 1 < n < 100, means values ​​of n from 2 can be up to 99) to find the number of times a prime number exists by expressing the factorial of have to do Like, we know, 5! = 120 = 2 * 2 * 2 * 3 * 5. Here 2 is 3 times, 3 is 1 time and 5 is 1 time. So if the input is 5 the output will be: 5! = (2, 3), (3, 1), (5, 1). Do you understand one thing that at the beginning of n ?Is it going to be a hassle to figure out the value of the factorial and then break the original product? Because the value of n is maximum 99 and integers cannot hold the factorial value of any number greater than 12. "Actually this program doesn't need to figure out the value of n!. Just do a little math. And put the prime numbers from 2 to 99 into an array."

I can't understand how will I find out factorial from prime number? Please give me some clue .

What I have tried:

Here, the author said,  "Actually this program doesn't need to figure out the value of n!. Just do a little math. And put the prime numbers from 2 to 99 into an array."  
My question is how will I find out the factorial from this array (prime number)
Suppose, I copy the prime numbers into an array
then ?
Posted
Updated 21-Jul-22 6:20am
Comments
Rick York 21-Jul-22 1:43am    
Either put the prime numbers into an array or determine if a number is prime on the fly. With a decent algorithm, performance should not be an issue.

This question is very poorly worded, but I think I get what it's looking for.

It wants to factor a factorial into a product of prime numbers, where each prime number also has an exponent.

n! = 1 x 2 x 3 x 4 x 5 x 6 ... x (n - 1) x n.

If you have an array that contains the prime numbers from 2 to 99, now do you see how you can use it? What can you do as you encounter the numbers in the above expression? 1? 2? 3? 4? 5? 6? Which of these are prime, and which aren't?
 
Share this answer
 
v2
Quote:
I can't understand how will I find out factorial from prime number?

May be it is because you don't.
The goal is not to find the factorial, but the product of primes that make the factorial.
Quote:
Please give me some clue .

The goal is to compute the product of primes from a factorial, but you know that a factorial is a product of integers. Do you really need to know the value of the factorial to get the answer. Something should ring in your head.

The job of programmer is about being smart, and this we can't teach you.
 
Share this answer
 
Comments
CPallini 21-Jul-22 2:09am    
5.
Patrice T 21-Jul-22 3:49am    
Thank you
Quote:
My question is how will I find out the factorial from this array (prime number)
Suppose, I copy the prime numbers into an array
then ?
This is not the right question. Actually computing the factorial is not requested (on the contrary, the requirements suggest avoiding it).

Now, how could you possibly produce the requested output without actually computing the factorial?
Consider, for instance, 5.

You know
5! = 5 * 4 * 3 * 2 * 1

That is
5! = 5 * (2*2) * 3 *  2 * 1

Producing the output
(2,3), (3,1), (5,1)


Note that, if you procede from 2 to 99, having computed the output for 5, makes you know a big deal of the output for 6, because
6! = 6 * 5! = (2*3) * 5!
 
Share this answer
 
Comments
Patrice T 21-Jul-22 3:50am    
+5 too
 
Share this answer
 
Comments
Patrice T 21-Jul-22 12:26pm    
Is it worth a solution ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900