its giving segmentation fault ,I hav precomputed all prime and then prefix sum it for range of values but not getting output.
Prime visits problemprime
in the function prime seive begin j with 2i, instead of ii
Code
but j=i*i is optimisation
in case you want to use j = i*i, please make i and j long long
when I am using from 2i its working but from i*i is optimisation in this its giving faullt
but why we are making I=i as long long i will be till 10p6 na which is in range ?
when i = 10^6, i * i would be 10^12, which cannot be stored in, int
but j will be 10^12 na so j should be long long but not i na?
i will be <=10^6 which is in range of int.so only j should be long long na?
when you’ll perform i*i the variable i would act as accumulator, so it needs to be long long as well
ok,one doubt till what no we can calculate prime by seive ?
usually in questions you wont have to calculate sieve till 10^6 maximum.
but there is miodified seive also for very large no so why are they ?
in the modified sieve the range remains the same, but prime numbers could start from numbers greater than 0. Please read about segement sieve for more.
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.