k = 2
and 20/2 = 10
so, for all the integer divisions, all i = 11 to 20 will produce n/i = 1; (last denominator)
so, you don't need to calculate for 11 to 20, you have 10x1 + 20/1 = 30; (for k = 1)
sum = 30;

k = 3
again 20/3 = 6
so, for all the integer divisions, all i = 7 to 10 will produce n/i = 2; (last denominator)
so, you don't need to calculate for 7 to 10, you have 4x2 + 20/2 = 18; (for k = 2)
sum = sum + 18 = 48;

k = 4
now, 20/4 = 5
so, for all the integer divisions, all i = 6 to 6 will produce n/i = 3; (last denominator)
so, you don't need to calculate for 6, you have 1x3 + 20/3 = 9; (for k = 3)
sum = sum + 9 = 57

as 4 is largest int within sqrt(20),
so lastly you have 1x4 + 20/4 = 9; (for k = 4)
sum = sum + 9 = 66 (ans);
no need to carry any more,

I think you'll now get it. Straight forward idea, will get in time easily. Try in this way for some larger numbers, may be you will be able to find a pattern.

Thanks

You should not always say what you know, but you should always know what you say.

k = 2
and 10/2 = 5
so, for all the integer divisions, all i = 6 to 10 will produce n/i = 1; (last denominator)
so, you don't need to calculate for 6 to 10, you have 5x1 + 10/1 = 15; (for k = 1)
sum = 15;

k = 3
again 10/3 = 3
so, for all the integer divisions, all i = 4 to 5 will produce n/i = 2; (last denominator)
so, you don't need to calculate for 4 to 5, you have 2x2 + 10/2 = 9; (for k = 2)
sum = sum + 9 = 24;

as k is the largest within sqrt(10);
so last we count for k = 3; for 3, one thing here to note that, 10/3 is also 3, so, in such cases, we have to consider once, cause otherwise it will be counted twice.
so, sum = sum + 3 = 27(ans)

for 10, we have the values (imagine RED is not yet counted, and GREEN is already counted, and BLUE is the current term)
k = 1; (10) + 5 + 3 + 2 + 2 + (1 + 1 + 1 + 1 + 1)
k = 2; 10 + (5) + 3 + (2 + 2) + 1 + 1 + 1 + 1 + 1
k = 3; 10 + 5 + (3) + 2 + 2 + 1 + 1 + 1 + 1 + 1;
so you see, 3 is to be counted once as it has no separate counterpart.
if k==n/k then you need to count once;

hope its now clear.

You should not always say what you know, but you should always know what you say.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
long long res, n, deno, i, temp, sum, test, sq;
scanf("%lld", &test);
while( test -- )
{
scanf("%lld", &n);
if( n == 0 )
{
printf("0\n");
continue;
}
sq = sqrt( n );
res = n;
sum = n;
deno = 1;
for( i = 2; i <= n; i ++ )
{
temp = n / i;
sum += ( res - temp ) * deno;
sum += temp;
deno = i;
res = temp;
if( n / ( i + 1 ) <= deno ) break;
}
if( n > 1 && n < 4 ) sum --;
printf("%lld\n", sum);
}
return 0;
}

hi "alamgir kabir"
i see your code .your procedure is not ok for this problem such as......
input :
2
100000
99999999
my Acc code output :
1166750
1857511487
your code faild for this case