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)