Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

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

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 1000000
bool prime[MAX];
int main(void){ 
  
  prime[0] = prime[1] = false;
  //memeset(prime,sizeof(prime),true);
  fill(prime,prime+MAX,true);
  long long int ans[MAX];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  int now=0;
  for(long long int i = 2 ; MAX > i ; i ++){
    ans[i] = now + prime[i];
    now += prime[i];
    //cout<<now<<" "<<ans[i]<<endl;
    if(prime[i]){
      for(long long int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  int n;
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	int i;
	int flag;
	int ans;
	
	scanf("%d", &n);
	
	ans = 0;
	while (n >= 2){
		flag = 0;
		for (i = n - 1; i >= 2; i--){
			if (n % i == 0){
				flag = 1;
			}
		}
		
		if (!flag){
			ans++;
		}
		
		n--;
	}
	
	printf("%d\n", ans);
	
	return (0);
}

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

class Sieve_of_Eratosthenes {
public:
	vector<bool> PN;
	
	Sieve_of_Eratosthenes(int x){
		init(x);
	}
	
	void huga(int t, int x){
		if(PN[t]) return;
		for(int i = t*t; i <= x; i+=t)
			PN[i] = true;
	}
	
	void init(int x){
		PN.resize(x+5);
		PN[0]=PN[1]=PN[4]=true;
		for(int i = 6; (i-1)*(i-1) <= x; i+=6)
		huga(i-1,x),huga(i+1,x);
		for(int i = 6; i <= x; i+=6)
			PN[i]=PN[i+2]=PN[i+3]=PN[i+4]=true;
	}
};

int main(){
	const int MAX = 1000000;
	int n;
	
	Sieve_of_Eratosthenes S(MAX);
	vector<int> sum(MAX);
	
	for(int i = 1; i < MAX; i++){
		sum[i] += sum[i-1] + !S.PN[i];
	}
	
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	return 0;
}

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

int main(){
	int num, cou, i, j, flag;
	
	while(cin >>num){
		cou = 0;
		for(i = 2; i <= num; i++, flag = 0){
			for(j = 2; j < i; j++){
				if(i % j == 0){
					flag = 1;
					break;
				}
			}
			if(flag == 0){
				cou++;
			}
		}
		if(num % 2 == 0) cou++;
		cout <<cou<<endl;
	}
	
	return 0;
}

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)count++;
			if((num % j) == 0)
			{
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
typedef long long LL;
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
const int N=1e7;
int sum[N],vis[N];
void initPrime()
{
    int num = 0, m = sqrt (N + 0.5);
    for (int i = 2; i <= m; ++i)
        if (vis[i] == 0)
            for (int j = i * i; j <= N; j += i) vis[j] = 1;
    sum[1]=0;
    for(int i=2;i<=N;i++)
    {
        if(!vis[i])  sum[i]=sum[i-1]+1;
        else   sum[i]=sum[i-1];
    }
//    for(int i=2;i<=10;i++)
//        cout<<"233  "<<sum[i]<<endl;
}
int main()
{
    int n;
    initPrime();
    while(~scanf("%d",&n))
        printf("%d\n",sum[n]);
    return 0;
}

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)count++;
			if(num % j == 0)
			{
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool prime[1000000];
		for(int l=2;l<=n;l++){
			prime[l] =true;
		}
		/* prime[0]=false;
		   prime[1]=false; */
		for(int i=2;i<=n;i++){
			if(prime[i]==true){
				for(int j=i+1;j<=n;j++){
					if(j%i==0) prime[j]=false;
				}
			}
		}
		int count=0;
		for(int k=2;k<=n;k++){
			if(prime[k]==true) count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
bool b[999999+1];

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

C++: #include<bits/stdc++.h>
using namespace std;

int arr[123456];

int main()
{

    int n;
    while(scanf("%d",&n)==1){
            memset(arr,0,sizeof arr);
    int k=0;
    int s=sqrt(n+1);

    for(int i=4;i<=n;i=i+2)
    {
        arr[i]=1;
    }
    for(int i=3;i<=s;i++)
    {
        if(arr[i]==0)
        {
            for(int j=i*i;j<=n;j=j+i)
            {
                arr[j]=1;
            }
        }
    }

    for(int i=2;i<=n;i++)
    {
        if(arr[i]==0)
        {
            k++;
        }
    }
    cout<<k<<endl;

    }


    return 0;
}

C++: #include<iostream>



using namespace std;



int n;

int prime[1000000];

int checked[1000000];

int primesum[1000000];

int result[30];

int datasets;



int main()

{

	prime[0] = 0;

	prime[1] = 0;

	primesum[0] = 0;

	primesum[1] = 0;



	for (int a = 2; a<1000000; a++)

	{

		prime[a] = 1;

	}



	for (int a = 2; a<1001; a++)

	{

		if (checked[a] == 0)

		{

			checked[a] = 1;

			for (int b = 2; b<a; b++)

			{

				if (a%b == 0)

				{

					prime[a] = 0;

					break;

				}

			}

			if (prime[a] == 1)

			{

				for (int c = 2 * a; c<1000000; c += a)

				{

					checked[c] = 1;

					prime[c] = 0;

				}

			}

		}

	}



	for (int a = 2; a<1000000; a++)

	{

		primesum[a] = primesum[a - 1] + prime[a];

	}



	while (cin >> n)

	{

		cout << primesum[n] << endl;

	}



	return 0;

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int p[MAX];
void f(){
	int n=0;
	for(int i=2;i<MAX;i++){
		if(p[i]==0){
			p[i] = ++n;
			for(int j=2;j*i<MAX;j++)
				p[j*i] = -1;
		}
		else p[i] = n;
	}
} 
int main(){
	int n;
	f();
	while(cin>>n){	
		cout<<p[n]<<endl;
	}
	return 0;
}