Counting divisors problem

all the codes related to factorization(sieve) are giving segmentation fault . please please help . am not getting whats happening

hi @gulatigarvita08

the major mistake which you are doing is
you make and array of size n means you can acces only [0-n-1] but you are trying to access p[n] which will give segmentation fault

after this correction you code run but only for small value of n

to run it on large value of n as well you have to make some modifications
and optimization
i have done those in code below
you can see

Modified Code

this is all about prime seive now in counting divisors
one change you have to do is
ans = ans * (cnt + 1);
multiply ans with cnt+1 not with cnt;

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

sir please send the modified code . the code which you sent is same and its giving segmentation fault.

sorry by mistake same link is copied :innocent:
i have update the link you can check now