Problem Description Link
so before test case you must generate two array for divisor and sum_of_divisor and and finally use a loop l
i=a to b and check that if any value i mod k is zero then add div+=divisor[i] and sum+=sum_of_divisor[i];
To generate divisor[] and sum_of_divisor[] you can use siv method
that method is bellow :
at first you must set each element 1 in divisor[] and sum_of_divisor[] after then
for(i=2;i<=max;i++)// max is array size
{
dividor[i]+=1;
sumdividor[i]+=i;
for(j=i+i;j<=max;j=j+i)
{
dividor[j]+=1;
sumdividor[j]+=i;
}
}
in min program you need only check
if(j%k==0)//where j=a to b
{
div+=dividor[j];
sum+=sumdividor[j];
}
div and sum are result.
Algorithm:
In this problem if you use more loop in main program to determine the number of divisor and sum of divisor may be you get time limit exit .so before test case you must generate two array for divisor and sum_of_divisor and and finally use a loop l
i=a to b and check that if any value i mod k is zero then add div+=divisor[i] and sum+=sum_of_divisor[i];
To generate divisor[] and sum_of_divisor[] you can use siv method
that method is bellow :
at first you must set each element 1 in divisor[] and sum_of_divisor[] after then
for(i=2;i<=max;i++)// max is array size
{
dividor[i]+=1;
sumdividor[i]+=i;
for(j=i+i;j<=max;j=j+i)
{
dividor[j]+=1;
sumdividor[j]+=i;
}
}
in min program you need only check
if(j%k==0)//where j=a to b
{
div+=dividor[j];
sum+=sumdividor[j];
}
div and sum are result.
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience