"Number theory, finding the Law" Uva 11526-h (N)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.