Light OJ 1234-harmonic number

Source: Internet
Author: User

Title Link: http://lightoj.com/volume_showproblem.php?problem=1234

give you a number n, let you beg

If this is a direct calculation, it must be tle, and if you store the answer with 1e8 array preprocessing, it must be mle.

So I use an array of 1e6 to store the answer for every 100 numbers, and then I give you an n at most 99 times a time.

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intMAXN =1e8;6 Doubleans[1000005], temp;7 intcont;8 intMain ()9 {Tenans[0] = Cont = TEMP =0; One      for(inti =1; I <= MAXN; i++) { ATemp = temp +1.0/i; -         ifI -==0) -Ans[++cont] =temp; the     } -     intt, N; -scanf"%d", &t); -      for(intCA =1; CA <= T; ca++) { +scanf"%d", &n); -         Doubleres = ans[n/ -]; +          for(inti = n/ -* -+1; I <= N; i++) { ARes + =1.0/i; at         } -printf"Case %d:%.10f\n", CA, res); -     } -}

Light OJ 1234-harmonic number

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.