Quote:
time limit exceeded
Your problem is that your method is too slow, because it is overkill.
You stop checking factors at n/2, do you have a reason to stop there ?
Think about this:
What is the minimum multiple of 3 that is not a multiple of 2 ?
What is the minimum multiple of 5 that is not a multiple of 2 or 3 ?
What is the minimum multiple of 7 that is not a multiple of 2, 3 or 5 ?
For each of those numbers, what is their product of primes ?
The answers should lead you to a more efficient upper limit.
Once you know that 2 is not a factor, do you need to test factors 4, 6, 8, 10, 12 ... ?
Advice: Define a function
IsPrime()
which will check if an integer is a prime or not. It will separate concerns in your code.
We do not do your HomeWork.