Uva-11526-h (N) (thinking, reducing enumerators)

Source: Internet
Author: User

Test instructions: Given n in the range of 32-bit signed integers, ask for n/1+n/2+n/3+n/4+......+n/n =?

Because of the loss of precision, so the calculation of some consecutive items is the same value, so try to find out for a certain value, which range is the value.

See Code comments

#include <cstdio>#include<cstring>#include<cctype>#include<cstdlib>#include<cmath>#include<iostream>#include<sstream>#include<iterator>#include<algorithm>#include<string>#include<vector>#include<Set>#include<map>#include<deque>#include<queue>#include<stack>#include<list>#defineFin freopen ("In.txt", "R", stdin)#defineFout freopen ("OUT.txt", "w", stdout)#definePR (x) cout << #x << ":" << x << ""#definePRLN (x) cout << #x << ":" << x << Endl#defineMin (A, B) a < b? A:b#defineMax (A, B) a < b? B:atypedefLong Longll;typedef unsignedLong LongLlu;Const intInt_inf =0x3f3f3f3f;Const intInt_m_inf =0x7f7f7f7f;Constll ll_inf =0x3f3f3f3f3f3f3f3f;Constll ll_m_inf =0x7f7f7f7f7f7f7f7f;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-6;Const intDr[] = {0,0, -1,1, -1, -1,1,1};Const intDc[] = {-1,1,0,0, -1,1, -1,1};Constll MOD = 1e9 +7;using namespacestd;#defineNdebug#include<cassert>Const intMAXN = -+Ten;Const intMaxt =10000+Ten;intMain () {ll n; intT; scanf ("%d", &T);  while(t--) {scanf ("%lld", &N); ll Sum=0;  for(LL i =1; I <=N;) {ll value= n/i;//value to be found at this timell lur = N/value;//n contains up to Lur value, rounded down (because it cannot be a decimal)Sum + = (lur-i +1) * value;//values within the range of I ~ lur are valuei = Lur +1;//reduce the amount of enumerators} printf ("%lld\n", sum); }    return 0;}

Uva-11526-h (N) (thinking, reducing enumerators)

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.