1245-harmonic number (II)---LightOJ1245

Source: Internet
Author: User

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&LT;=SQRT (n); i++) {sum+ = n/i; }         for(intI=1; I&LT;=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

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.