Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		flag := false
		count := 0

		for i := 3; i <= num; i += 2 { //1を除く入力値以下の数字
			for j := 3; j < i; j += 2 {
				if i%j == 0 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count + 1)
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
#define MAX 1000000


int main(){
	bool work[MAX];
	int num, ans = 0;

	// 入力
	cin >> num;

	// 初期化
	for(int i = 0; i < MAX; i++){
		if(i < 2){
			work[i] = false;
		}else{
			work[i] = true;
		}
	}

	// エラトネスのふるい
	for(int i = 2; i < sqrt((double)MAX) + 1; i++){
		if(work[i] == true){
			for(int j = i * 2; j < MAX; j += i){
				work[j] = false;
			}
		}
	}

	// 計算
	for(int i = 0; i <= num; i++){
		if(work[i] == true){
			ans++;
		}
	}

	// 出力
	cout << ans << endl;

	return 0;
}

C++: #include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int pt[1000000];

int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 2; i <= n; i++) if (pt[i] == 0) {
        ans++;
        for (int j = i+i; j <= n; j+=i) pt[j] = i;
    }
    printf("%d\n", ans);
    return 0;
}

C++: #include<cstdio>
#include<cstring>
int main(){
 int n,cnt=0;
 scanf("%d",&n);
 int a[n+1];
 memset(a,-1,sizeof(int)*(n+1));
 for(int i=2;i<=n;i++){
 if(a[i]==-1){ cnt++;
 for(int j=i;j<=n;j=j+i) a[j]=0;}
}
printf("%d\n",cnt);
return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
	char prime[999999];
	for (int i = 0; i <= 999999; i++)prime[i] = '1';
	prime[0] = '0';
	prime[1] = '0';
	for (int i = 2; i*i <= 999999; i++)
	{
		if (prime[i] == '1')
		{
			int j = i * 2;
			while (j <= 999999)
			{
				prime[j] = '0';
				j += i;
			}
		}
	}
	int n;
	while (cin >> n)
	{
		int sum = 0;
		for (int i = 0; i <= n; i++)
		{
			if (prime[i] == '1')sum++;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		count[i]=so[i]=0;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=1;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]>0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=1;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+1-so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

void sieve(int n, vector<int> &primes)
{
    vector<bool> v(n + 1, true);

    // check
    for (int i = 2, end = sqrt(n); i <= end; i++) {
        if (!i)
            continue;
        for (int j = i + i; j <= n; j += i)
            v[j] = false;
    }

    for (int i = 2; i <= n; i++)
         if (v[i])
            primes.push_back(i);
}

int main()
{
    vector<int> primes;
    vector<int> inputs;
    int i;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        for (i = 0; i < primes.size(); i++) // find
            if (primes[i] == x) {
                i++;
                break;
            } else if (primes[i] > x)
                break;
        cout << i << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

bool isPrime(int x) {
    if (x==2) {
        return true;
    }
    if (x<2 || x%2==0) {
        return false;
    }
    for (int i=3; i*i<=x; i+=2) {
        if (x%i==0) {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    int cnt;
    while (cin >> n) {
        cnt=0;
        for (int i=0; i<=n; i++) {
            if (isPrime(i)) {
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

C++: #include<iostream>

using namespace std;



bool Prime(int n)
{
	if((n==1)||(n==0))
	{
		return false;
	}
	for(int i=2;i<=n-1;++i)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		for(int i=0;i<=n;++i)
		{
			if(Prime(i))
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

#define priMAX 1000000

vector<int> sieve_of_eratosthenes(int n) {
	vector<int> primes(n);
	for (int i = 2; i < n; ++i)
		primes[i] = i;
	for (int i = 2; i*i < n; ++i)
	if (primes[i])
		for (int j = i*i; j < n; j+=i)
			primes[j] = 0;
	return primes;
}

int main(){
	vector<int> primes = sieve_of_eratosthenes(priMAX);
	vector<int> all(priMAX);
	int cc = 0;
	for(int i=0; i<priMAX; i++){
		if(primes[i]) cc++;
		all[i] = cc;
	}
	int n;
	while(cin>>n){
		cout<<all[n]<<endl;
	}
	return 0;
}

C++: /*#include <stdio.h>
  int main(){
    int a,b,c,d,n,sum=0;
      while(scanf("%d",&n) != EOF){
       for(a=0;a<10;a++){
          for(b=0;b<10;b++){
             for(c=0;c<10;c++){
                for(d=0;d<10;d++){
                    if(a+b+c+d==n)
                        sum++;
                          }
                            }
                             }
                               }
                                printf("%d\n",sum);
                                 sum=0;
                                   }
return 0;
}*/#include <stdio.h>
  int main(){
   int i,j,n,hantei=0;
   int sum=0;
    while(1){
scanf("%d",&n);
if(n != EOF){
break;
}
    for(i=2;i<=n;i++){
      for(j=2;j*j<=i;j++){
        if(i%j != 0 || i == j){
            hantei += 0;
               }else{
                  hantei += 1;
                    }
}
if(hantei == 0){
sum++;

}
hantei=0;
}
printf("%d\n",sum);
sum=0;
hantei = 0;
}
return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define MAX_SIZE 1000100
#define N 999999
int preme[MAX_SIZE];

int main(int argc, char *argv[]) {
	int index = 0;
	for(int i = 0; i < MAX_SIZE; i++)
		if(i % 2)
			preme[i] = 1;
		else {
			preme[i] = 0;
		}
	preme[2] = 1;
	for(int i = 3; i <= 999999; i += 2) {
		if(preme[i]) {
			for(int j = i + i; j <= 999999; j += i)
				preme[j] = 0;
		}
			
	}
	//freopen("data.txt", "r", stdin);
	int n;
	while(~scanf("%d", &n)) {
		long count = 0;
		for(int i = 1; i <= n; i++)
			if(preme[i])
				count++;
		cout << count << endl;
	}
		
}

C++: #include<stdio.h>
#include<string.h> 
#define MAX 10000000

int prime[MAX];
bool isprime[MAX];


int main()
{
	long n;
	int primeSize=0;
	
	while(scanf("%d",&n)!=EOF)
	{
		memset(isprime,1,sizeof(isprime));
		isprime[0]=isprime[1]=0;
		for(int i=2;i<=n;i++)
		{
			if(isprime[i]) prime[++primeSize]=i;
			for(int j=1;j<=primeSize&&i*prime[j]<=n;j++)
			{
				isprime[i*prime[j]]=0;
				if(i%prime[j]==0) break;
			}
		}
			printf("%d\n",primeSize);
	}
}

C++: #include <iostream>
#include <math.h>

bool is_prime(int n,int r);

int main(void) {
	using namespace std;
	int x;
	int count;
	while (cin >> x) {
		count = 0;
		double r = pow(x, 0.5);
		for (int i = 2; i <= x; i++) {
			if (is_prime(i,r))count++;
		}
		cout << count << endl;
	}
	return 0;
}



bool is_prime(int n,int r) {
	static int flag = 0;
	static int list[78498];
	static int count = 0;
	if (flag == 1) {
		for (int i = 0; i < count; i++) { 
			if (list[i] >r) {
				return true;
			}
			if (n % list[i] == 0) {
				if (n == list[i]) {
					
					return true;
				}
				
				return false;
			}
		}

	}
	flag = 1;
	list[count] = n;		
	count++;
	
	return true;
}