how to optimise
https://ide.codingblocks.com/s/69293
Not so Easy Maths
Hi
You brute force approach is taking O(n) time, n is till 10^18 so this will not work you can do at max 10^8 iterations in 1 sec.
Approach for this question is :This question is based on inclusion exclusion principle (Set theory)
let a,b,c,d,e,f… represent set of prime numbers less than 20.
Now you have to find
a union b union c union d…
this can be found by inclusion exclusion principle.
In case you need explanation do post it.
Video reference https://www.youtube.com/watch?time_continue=122&v=tMRZ6gqFYdg
Hit like if you get it
Cheers!
Hi
As you are not replying to this thread i’m marking this as resolved you can reopen it later if you still have doubt.
Cheers!
I have used the inclusion exclusion principle pls see its showing wrong answer.
Hi
you logic is incorrect, I find a lots of mistake, please do a dry run to your code for given inputs only its showing wrong ans.
hints---->
-questions works for multiple test cases but in your code you have considered that.
- for n=5 you output is 0 but it should be 4 ( if n== isprime then you are simply returning 0 that’s wrong)
watch this video again https://www.youtube.com/watch?time_continue=122&v=tMRZ6gqFYdg
if you are still not able to you can PM me over WhatsApp.
Hit like if you get it!
Cheers!