Please check my code - https://ide.codingblocks.com/s/191703
Wrong answer and time limit exceed
@souravmunjal2000 Hey you need to use seive for calculating all the prime numbers till N, to save time. Also for calculating the sum of digits of prime number you are directly adding the complete number which is wrong.
eg.
22 (2*11)
sum of prime numbers digit= 2+ 1+ 1=4
sum of digits=2+2=4
but in your program sum of prime would be 2+11(wrong)
If this solves your doubt mark it as resolved.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
- since n is of order 10^9 you cannot seive till n/2;
- you were printing “YES” or “NO”. whereas in the question you need to print 1 or 0;
- Sieve is not needed to do prime factorization.
Have a look at the code https://ide.codingblocks.com/s/230406
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.