Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

C++: #include <stdio.h>

int main(){
	int sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0)break;
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

const int max=500000;
int prime[max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<max; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<max; j+=i) prime[j]=0;
    }
    for(int i=1; i<max; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main() {
	int n,ans=0,i,count=0;
	while (cin >> n) {
		for (i = 2; i <= n; i++) {
			for (int j = 2; j <= i; j++) {
				if (i%j == 0) {
					count++;
				}
			}
			if (count == 1) {
				ans++;
			}
			count = 0;
		}
		cout << ans << endl;
		ans = 0;
	}
	return 0;
}

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

bool IsPrime(int n){

    if(n % 2 == 0)
        return false;
 
    for(int i = 3; i * i <= n; i += 2)
         if(n % i == 0)
            return false;
    return true;
}
int CheckNum(int input){
	int count = 1;

	for(int i = 2; i < input; ++i){

		if(IsPrime(i)) ++count;
	}
	return count;
}
int main() {
	int input;

	while(cin >> input){
	cout << CheckNum(input) << endl;
	}
}

C++: #include <iostream>

using namespace std;

const int MAX = 1000000;
bool p[MAX];
int num[MAX];

void prepare() {
    for (int i=0; i<MAX; ++i) p[i] = true;
    p[0] = p[1] = false;
    for (int i=2; i*i<MAX; ++i) {
        if ( ! p[i]) continue;
        for (int j=i*i; j<MAX; j+=i) {
            p[j] = false;
        }
    }
    int sum = 0;
    for (int i=0; i<MAX; ++i) {
        if (p[i]) sum ++;
        num[i] = sum;
    }
}

int main() {
    prepare();
    int n;
    while (cin >> n) {
        cout << num[n] << endl;
    }
    return 0;
}

C++: #include <cstdio>
const int N=1000000;
bool p[N];int pN[N];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)p[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i]=c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		if ( n <= 0 )
			cout << "0" << endl;
		
		vector <bool> p(n+1, true);

		p[0] = p[1] = false;
		for ( int i = 4; i <= n; i += 2 )
		{
			p[i] = false;
		}

		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
			{
				for ( int j = i+i; j <= n; j += i )
				{
					p[j] = false;
				}
			}
		}

		int kotae = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
				kotae++;
		}

		cout << kotae << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;
int main(){
	bool n[1000000];
	for(int i=0; i<1000000; i++){ n[i]=1; }
	n[0]=0;
	n[1]=0;

	for(int i=2; i<1000000; i++){
		if(n[i]==0){ break; }
		if(n[i]==1){
			for(int j=i*2; j<1000000; j+=i){ n[j]=0;	}
		}
	}

	int num;
	int count;
	while(cin >> num){
		count = 0;
		for(int i=2; i<=num; i++){
			count += n[i];
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		i = 3;
		cnt = 0;
		fg = 0;	
		
		if ((int)log10(n) == 3) {
			cnt = 167;
			i = 1001;
		}
		else if ((int)log10(n) == 4) {
			cnt = 1228;
			i = 10001;
		}
		else if ((int)log10(n) == 5) {
			cnt = 9591;
			i = 100001;
		}
		else if ((int)log10(n) == 6) {
			cnt = 78497;
			i = 1000001;
		}


		for (; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		if (n >= 2)
			cnt++;
		cout << cnt << endl;
	}

	return 0;
}

C++: 



#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

/*
int main(void)
{
	int n;
	vector<int> vecPrime;

	while (cin >> n)
	{
		// vectorの破棄
		vecPrime.clear();

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			vecPrime.push_back(2);
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい
			int size = vecPrime.size();
			for (int j = 1; j < size && vecPrime[j] < sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % vecPrime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				vecPrime.push_back(i);
			}
		}

		cout << vecPrime.size() << endl;
	}

	return 0;
}
*/


#define SIZE 100000

int main(void)
{
	int n;
	int prime[SIZE] = {0};

	while (cin >> n)
	{
		int ans = 0;

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			prime[0] = 2;
			ans++;
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい(sqrtの部分が < ではwrongAnswer)
			for (int j = 1; j < ans && prime[j] <= sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % prime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				prime[ans] = i;
				ans++;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#define MAX_N 1000001

bool IsPrime[MAX_N];
int cnt[MAX_N];

// エラトステネスの篩
void get_primes() {
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i*i <= MAX_N; i++) {
        if (IsPrime[i]) {
            for (int j = i*i; j <= MAX_N; j += i) {
                IsPrime[j]= false;
            }
        }
    }
}

int main() {
    int n;

    memset(IsPrime, 1, sizeof(IsPrime));
    get_primes();

    for (int i = 0; i <= MAX_N; i++) {
        if (IsPrime[i]) { cnt[i]++; }
    }
    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    while (scanf("%d", &n) != EOF) {
        printf("%d\n", cnt[n]);
    }

    return 0;
}

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

bool IsPrime(int n) {
    for(int i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
	// your code goes here

	int n;
	while(1){
		cin >> n;
		if(cin.eof()){
			break;
		}
		int count = 0;
		for(int i=2;i<=n;i++){
			if(IsPrime(i)){
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[100000]={0};
	for(int i=2;i<100000;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		if(flag){
		sosu[i]=1;
		}
	}
	while(cin>>n){
	ans=0,cnt=0;
	for(int i=2;i<=n;i++){
		if(sosu[i]==1){
		ans++;
		}
	}
	cout<<ans<<endl;
	}
    return 0;
}