11526 - H(n)
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11526 - H(n)
For n=2147483647, the output should be 46475828386. Read this thread for ideas on a faster algorithm.
Check input and AC output for thousands of problems on uDebug!
Re: 11526 - H(n)
How to avoid time-limit exceed in this problem. All I know is the most obvious procedure will give time-limit exceed error. So where can I learn the faster algorithm from, pleeeeze anyone...
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11526 - H(n)
Read this thread for ideas on a faster algorithm.
Check input and AC output for thousands of problems on uDebug!
Re: 11526 - H(n)
Why is this code getting WA?
Anyone, please help!!!!
Code: Select all
#include <stdio.h>
#include <math.h>
int main()
{
int n, T, sqrtn, i, l1, l2, k;
unsigned long long sum, sum2;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
if(n < 0)
n = -n;
sum = n;
sqrtn = sqrt(n);
k = 1, l2 = n;
for(i=2; i<=sqrtn; i++)
{
l1 = n/i;
sum += l1;
if(l2 != i)
sum += k * (l2 - l1);
l2 = l1;
k++;
}
while(i <= l2)
{
sum += n / i;
i++;
}
printf("%llu", sum);
if(T)
printf("\n");
}
return 0;
}
Re: 11526 - H(n)
I sent you private message. Check it
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman