http://lightoj.com/volume_showproblem.php?problem=1245
The sum of a number n divided by 1 to n
Analysis: Violence is certainly not possible, we can first ask for the number of 1~SQRT (n), and then the n divided by the number of 1~SQRT (n) and
The complexity of the 2*SQRT (n) is the only thing that counts.
Finally, we have to rule out extra,
#include <stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespaceStd;typedefLong Long intLL;#defineN 10001000#defineESP 1e-8#defineINF 0x3f3f3f3f#defineMemset (A, B) memset (A,b,sizeof (a))intMain () {intT, t=1; scanf ("%d", &T); while(T--) {LL n; scanf ("%lld", &N); LL sum=0; for(intI=1; I<=SQRT (n); i++) {sum+ = n/i; } for(intI=1; I<=SQRT (n); i++) {sum+ = (n/i-n/(i+1)) *i; } if(N/(int) sqrt (n) = = (int) sqrt (n)) sum-= (N/SQRT (n)-n/(sqrt (n) +1)) *sqrt (n); printf ("Case %d:%lld\n", t++, sum); } return 0;}
1245-harmonic number (II)---LightOJ1245