Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	a, _ := strconv.Atoi(scanner.Text())
	return a
}

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: /**************************
½ªg¦éBÁ³È¢æ¤É
**************************/

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

int main()
{
	
	long long int k,p[100000];
	long long int n;
	p[0]=2;
	while(cin>>n){
		if(n<0){
			break;
		}
	k=1;
	int r=(int)sqrt((float)n);
	//mFpfÍÌÜÅKv
	//ÜÅÜí·
	for(int i=3;i<r;i++){
		//»êÜÅÌfÅmF
		for(int j=0;j<k;j++){
			//ÅúÜÅêÈ©Á½çJEgµÄAmFpfÌzñÉi[
			if(i%p[j]==0){
				break;
			}else if(j==(k-1)){
				p[k]=i;
				k++;
			}
		}
	}
	long long int r_k=k;
	for(;r<=n;r++){
		for(long int i=0;i<r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==(r_k-1)){
				k++;
			}
		}
	}
	if(n==1){
		k=0;
		cout<<k<<endl;
	}else if(n==2){
		k=1;
		cout<<k<<endl;
	}else if(n==3){
		k=2;
		cout<<k<<endl;
	}else{
	cout<<k<<endl;
	}
	}
}

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

static const int DATA_NUM = 1000001;
vector<int> prime;
bool isPrime[DATA_NUM];
void primeCalc()
{
	for(int i = 0; i < DATA_NUM; ++i)
	{
		isPrime[i] = true;
	}
	isPrime[0] = isPrime[1] = false;
	for(int i = 0; i < DATA_NUM; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < DATA_NUM; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	primeCalc();
	int n;
	while(cin >> n)
	{
		int ans = 0;
		for(int i = 0; i <= n; ++i)
		{
			if(isPrime[i])
			{
				++ans;
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<string.h>
using namespace std;
const int N=1000000;
bool isprime[N];
int prime[N];
int k=0;
void init()
{
    isprime[0]=isprime[1]=false;
    for(int i=2;i<N;i++)
    {
        if(isprime[i]) prime[k++]=i;
        for(int j=0;j<k;j++)
        {
            int d=i*prime[j];
            if(d>=N) break;
            isprime[d]=false;
            if(i%prime[j]==0) break;
        }
    }
}
int main()
{
    int n;
    memset(isprime,true,sizeof(isprime));
    init();
    while(cin>>n)
    {
        int i;
        for(i=0;i<k;i++)
            if(n<prime[i])
                break;
        cout<<i<<endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		bool *flag = new bool[n+1]();
		for(int i=2;i<n;++i)
		{
			if (flag[i])
			{
				continue;
			}
			for(int j=i*2;j<n;j+=i)
			{
				flag[j] = true;
			}
		}
		flag[0]=true;flag[1]=true;
		for(int i=0;i<=n;++i)
		{
			if(!flag[i])
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
}

C++: // PrimeNumber.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int n, count,k;

	while(cin >> n){
		count = 1;
		k = 0;

		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j <= sqrt((double)i); j += 2)
			{
				if(i%j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0){
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: //筛法也快不到哪里去啊
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
bool prime(int cur)
{
    if(cur==1||cur==0)return false;
    for(int i=2;i<=sqrt(cur);i++)
    {
        if(cur%i==0)
        {
            return false;
        }
    }
    return true;
}
int cnt[1000005];
int main()
{
    for(int i=1;i<=1000005;i++)
    {
        if(prime(i))cnt[i]=cnt[i-1]+1;
        else cnt[i]=cnt[i-1];
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        cout<<cnt[n]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#include <vector>
using namespace std;
bool flag[10000000];
int n, hasil;
int main(){

	for(int i = 1; i <= 1000000; i++){
		flag[i] = true;
	}
	for(int i = 2; i <= 1000; i++){
		if(flag[i] == true){
			for(int u = i*i; u <= 1000000; u = u + i){
				flag[u] = false;
			}
		}
	}
	flag[1] = false;
	while(cin >> n){
		hasil = 0;
		for(int i = 1; i <= n; i++){
			if(flag[i])
				hasil++;
		}
		cout << hasil << endl;
	}
	return 0;
}

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

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=1000000;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x)
{
	if (x < 2)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	for (int i = 3; i <= (int)sqrt(x); i+=2)
		if (x%i == 0)
			return false;
	return true;
}
int main()
{
	int n;
	cin >> n;
	int count = 0;
	for (int i = 1; i <= n; i++)
		if (isPrime(i))
			count++;
	cout << count << endl;
}

C++: ???#include <iostream>

using namespace std;

int main()
{
	unsigned int  n;
	cin >> n;
	unsigned  int num, count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(int j = 2; j < num; j++)
		{
			if(num % j == 0)
			{
				break;
			}
			if(num - 1 == j)
			{
				count++;
			}
		}
		if(num == 2)
		{
			count++;
		}
	}
	cout << count << std::endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	bool num[1000000] = {0};
	for(int i=2; i<1000; i++){
		if(!num[i]){
			for(int j=i*2; j<1000000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n/2+1; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main (){
    
    /*?´???°???????´?????????????*/
    vector<int>Primenumber(MAX+1,0);
    /*?´???°???????´???????????????????*/
    int n;
    while(cin >> n){
        bv check(MAX+1,true);
    for(int i = 2; i<=n;i++){
        if(check[i]){
            /*true?????£?????¨???????????°????????????false??§*/
            for(int j = 2;i*j<=n;j++)
                check[i*j] = false;
        }
    }
    int ans = 0;
    for(int i = 2;i<=n;i++)
        if(check[i])
            ans++;
    cout << ans << endl;
    }
}

C++: #include"stdio.h"
#define nmax 1000000
int ans[nmax];
bool is_prime[nmax + 1];

void sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = 0;
	ans[0] = ans[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			p++;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
		ans[i] = p;
	}
}
int main()
{
	sieve(nmax);
	int n,m=0;
	for (; scanf("%d", &n) == 1;) {
		printf("%d\n", ans[n]);
	}
	return 0;
}