Algorithm of 11876 - N + NOD (N)

Problem Description Link
Algorithm:
To solve this problem you should generate divisor and NOD sequence before get input otherwise you may get time limit exit
NOD value sequence generate by this produce :
Nodvalue[i]=Nodvalue[i-1]+dividor[Nodvalue[i-1]];

when you get input just find the index of value A and B
and difference of index B and A is O/P.
you can use binarry search for find speedy  index of A and B .
NB: generate the devisor you can use this function

void generate()
{
    long int i, j, k;
    for(i=0;i<=max;i++)
        dividor[i]=1;
    for(i=2;i<=max;i++)
    {
        dividor[i]+=1;
        for(j=i+i;j<=max;j=j+i)
           dividor[j]+=1;
    }
}
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience