Nefu 117-Number of primes (prime number theorem)

Source: Internet
Author: User

Title Address: Nefu 117
Test instructions: Give you an integer N (n<1e9), and if the number of primes in an integer less than 10^n is π (n), the number of digits of π (n) is obtained.
Idea: The data volume of the topic is very large, directly seek affirmation tle, so consider the prime number theorem.
Prime theorem: Remember that π (N) is a number of <=n, then there are
A number of digits X can be used LG (x) + one, so the subject of LG (N/INN) +1 is the request, because n=10^n, so the number of bits =LG (10^n)-lg (in (10^n)) +1=n-lgn-lg (in (10)) +1.

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;Const intmaxn=1e6+Ten;intMain () {DoubleN,m; while(~scanf("%LF", &n)) {m= (nlog10(n)-log10(Log(Ten)));printf("%d\n",(int) m+1); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nefu 117-Number of primes (prime number theorem)

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.