No of divisors problem

sir i am practicing a question related to number theory and it is giving correct output for maximum cases but still partially accepting on submission. i am not able to find the error . so please take a look into my code and suggest the corrections . if possible then correct there.

question >
https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practice-problems/algorithm/gotta-beat-em-all/

my code —> https://ide.codingblocks.com/s/480414

hello @tejuschaturvedi0

there is no need of storing all primes.

use one array that will store the count of divisiors.

now when u are running sieve loop.
if i is a number then go to all its multiple and increase its divisor count by 1.

after the iteration is done the array will hold count of divisors of each number and then simply use this array to answer the query.

int divisor[n+1]={0};
 for(i=1;i<=n;i++)
 {
     for(j=i;j<=n;j+=i)
       divisor[j]++;
 }


now divsior[i] will give u count of divisors of number i

sir i am not able to make the code for it. so can you please edit my code with particular corrections so that i can understand flow of code.

u need to change ur complete logic.
and here i have explained the same.

sir i have made the code as you said but it is not giving correct output. please mark my error . my code --> https://ide.codingblocks.com/s/480719

j is starting from i . u are starting it from 1

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.