The original did the title again to see or did not think out, it seems that at that time must not really understand. This review feels more thorough.
The online puzzle is almost a version, and it feels a little bit ridiculous. According to n=20 guess?
Okay, well, I guess that's a weird formula based on one. In fact, the problem of a little bit of a law is good. Of course, there may not be a formula method, but it's easier to understand.
You use the n=20 example, then I also use. But that's what I thought.
sum = 0;
We consider how much I is when n/i = 1:20/1 = 20, so I <= 20, and 20/2 = 10, so i > 10, that is, < I <= 20 o'clock, n/i = 1; sum + = 1* (N/1-N/2 + 1);
Similarly we consider how much I is when n/i = 2:20/2 = 10, so I <= 10, and 20/3 = 6, so i > 6, i.e. 6 < I <= 10 o'clock, n/i = 2; sum + = (N/2-N/3 + 1);
Continue our consideration of how much I is n/i = 3:20/3 = 6, so I <= 6, and 20/4 = 5, so i > 5, i.e. 5 < I <= 6 o'clock, n/i = 3; sum + = (N/3-N/4 + 1);
Do you find the rules now?
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace Std;
typedef unsigned long long ull;
void Solve (ull n)
{
ull res = 0;
for (ull i = 1; i <= n;)
{
Res + = i* (n/i-n/(i+1));
i = n/(i+1);
}
cout << Res << Endl;
}
int main ()
{
int T; scanf ("%d", &t);
while (t--)
{
ull N; scanf ("%i64u", &n);
Solve (n);
}
return 0;
}
"Number theory, finding the Law" Uva 11526-h (N)