2092.] [2016.11.12PJ simulation game

Title Description

Guyu Guo and Tube Lu are playing a game: Lu meditation x number between 1 and n, then Guo try to guess the number.
Guo m can put forward a question: "Are unknowns yi be divisible?"
Game in accordance with the following procedure: Guo given first of all to ask him questions m, and Lu followed all questions with "yes" or "no "answer. After getting the answer m question, Guo will give his guess.
Guo wrote a program to help him to the best way to raise this question m, and now he wanted to know under guarantees a definitive answer, a minimum number of questions that can be asked of a minimum m. But Guo was busy eating his beautiful sister school to send candy and no time to change the code (to send candy sister very much, so there are a lot of candy is about to expire), so he found you, I hope you can help him solve this problem.

Entry

Row, an integer n

Export

Row, an integer m

Data range limit

For 20% of the data: 1 ≤ n ≤ 20
data for 60%: 1 ≤ n ≤ 1000
data for 100%: 1 ≤ n ≤ 100000

Code

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<cmath>
using namespace std;
bool f[100010];
long long w;
int n,ans;
inline int read()
{
    int ret = 0,w = 0; 
	char ch = 0;
    while(!isdigit(ch)) 
	{
		w |= ch == '-';
		ch = getchar();
	}
    while(isdigit(ch)) 
	{
		ret = (ret << 3) + (ret << 1) + (ch ^ 48);
		ch = getchar();
	}
    return w ? -ret : ret;
}
inline void write(int ret)
{
     if(ret < 0)
     {
     	putchar('-');
		ret = -ret;
	 }	
     if(ret > 9) 
	 	write(ret / 10);
     putchar(ret % 10 + '0');
}
int main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	n = read();
	memset(f,false,sizeof f);
	f[1] = true;
	ans = 0;
	for(int i = 2;i <= n;i++)
		if(f[i] == false)
			for(int j = 2;j <= n / i;j++)
				f[i * j] = true;
	for(int i = 2;i <= n;i++)
		if(f[i] == false)
		{
			w = i;
			while(w <= n)
			{
				ans++;
				w *= i;
			}
		}
	write(ans);
}

Guess you like

Origin blog.csdn.net/qq_40155097/article/details/95314558