[2020 winter game gmoj2092] [] [] screen Erichsen

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.

Entry

Row, an integer n

Export

Line, an integer m (m represents the minimum asking a question)

Sample input

[1] Sample input
4

[2] Sample input
8

Sample Output

[1] Sample Output
3

[2] Output Sample
6

Sample 1 explained:
Guo question in turn can be divisible by 2, 3, you can get to determine the answer.
For example, Lu answer can be divisible by 2, 4, can not be divisible by 3, it is determined that the answer is 4
Sample 2 explained:
Guo question in turn can be 2,3,4,5,7,8 divisible, a total of six times.

analysis

In fact, this question I started to see is completely ignorant of the force, the sample can not read.
After pointing ymw big brother, I understood why. . .

We can see a pattern: To ask the number is less than equal to n k ^ p. k is a prime number, p is a positive integer.

ymw chiefs also pointed out: This problem usually guess the conclusion then prove that you can push a few small examples.
As for how to prove this rule, I did not quite understand, put a few shots everyone to see: Here Insert Picture Description
Here Insert Picture Description
when I wrote the code:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100001]={0},s[100001]={0};
long long ans,sum;
int pdzs(int x)
{
	int p=0;
	for(register int k=2;k<=x-1;k++)
	{
		if(x%k==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
//	freopen("game.in","r",stdin);
//	freopen("game.out","w",stdout);
	cin>>n;
	for(register int i=2;i<=n;i++)
	{
		if(pdzs(i)==0) continue;
		else
		{
			for(register int j=1;j<=n;j++)
			{
				sum=pow(double(i),double(j));
				if(sum<=n&&a[sum]==0)
				{
					
					ans++;
					a[sum]=1;	
				}
				else break;
			}
		}
	}
	cout<<ans;
	fclose(stdin);
	fclose(stdout);
    return 0;
}

The results overtime. . . . .
dalao introduced the Egyptian style sieve method . It is to weed out all multiples of primes. I had a variant: to weed out multiple primes, leaving the power of prime numbers, the last not to be screened is the number of the answer, you can accumulate.

The Code

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int ip[100001]; 
long long t;
int main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	int n;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		ip[i]=1;
	}
    for(long long i=2;i<=n;i++)
    {
    	if(ip[i]==1)
    	{
    		for(int j=2*i;j<=n;j+=i)
    		{
    			ip[j]=0;
			}
			for(long long k=i*i;k<=n;k*=i)
			{
				ip[k]=2;
			}
		}
	}
//	for(int i=1;i<=n;i++)
//	{
//		cout<<ip[i]<<' ';
//	}
	for(int i=2;i<=n;i++)
	{
		if(ip[i]==1||ip[i]==2) t++;
	}
	cout<<t;
	fclose(stdin);
	fclose(stdout);
    return 0;
}

Published 63 original articles · won praise 61 · views 5472

Guess you like

Origin blog.csdn.net/dglyr/article/details/104224319