Lets play game ...... m getting 2 WA


the logic seems fine.

@imavneet
Your code for sieve is fine
The solution for the problem is just printing 2^(P-1)
Where P is number of prime numbers till N
See this for further detail

@Aarnav-Jindal-1059677350830863 this code is a bit difficult to understand … could you tell me what difference would it make if i start with 2 and subtract 1 from k later?
could you please tell where the error is … so that i can correct my code

@imavneet
This is what I wanted to show you in that post

Our objective is to factor n! into p and q such that hcf(p,q)=1 and p<q. so we calculate number of distinct primes in n!
let prime factorisation of n!= (p1)^x1 * (p2)^x2 … (pk)^xk
now for each i, (pi)^xi can either go in p or q. Hence 2^k ways. but as we want p<q. therefore only 2^(k-1) ways. That’s why in code, counting primes is started from 3 because ultimately we would have to subtract 1 from k.

Your code is doing a lot of unnecessary computation. No benefit trying to solve a question wrong way buddy. Better learn the correct approach and move ahead no :slight_smile:

If there is anything else you need help me please let me know else please close the doubt

@Aarnav-Jindal-1059677350830863 i will try this way … thank you :blush:

1 Like