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<stdio.h>
#include<math.h>
#define MAX 10000
int main()
{
	int i, j,n,s;
	bool a[MAX];

	for (i = 0; i < MAX; i++) {
		a[i] = i <= 1 ? false: true;
	}
	for (i = 2; i < sqrt(MAX); i++) {
		if (a[i]) {
			for (j = 0; i*(j + 2) < MAX; j++) {
				a[i*(j + 2)] = 0;
			}
		}
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &n);
	}
	s = 0;
	for (i = 0; i < n; i++) {
		s = s + a[i];
	}
	printf("%d",s);
}

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

int main()
{
	int counter=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<'0'<<endl;
			break;
		}

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

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

int main(void) {
    int N=999999;
    int p[N] , s[N];
    p[0]=0 , s[0]=0;
    for (int i=1; i<N; i++){
        p[i] = 1;
        s[i] = 0;
    }
    for (int i=1; i<N; i++){
        cout << i;
        if (p[i]==1){
            int n=i+1 , m=2*n;
            while (m<=N){
                p[m-1] = 0;
                m += n;
            }
        }
    }
    
    for (int i=1; i<N; i++){
        s[i] = s[i-1]+p[i];
    }
    int n;
    while (1){
        cin >> n;
        if (cin.eof())
            break;
        cout << s[n-1] << endl;
    }
    return 0;
}

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

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

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

C++: #include<cstdio>
using namespace std;
#define MAX 1000000
int prime[MAX];
bool is_prime[MAX];
int sieve(int n){   //埃氏?
   int p=0;
   for(int i=0;i<=n;i++)
    is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
   for(int i=2;i<=n;i++){
    if(is_prime[i]){
        prime[p++]=i;    //??素数的个数和素数的?
        for(int j=2*i;j<=n;j+=i)
            is_prime[j]=false;
    }
   }
   return p;
}
int main()
{
  int num;
  while(scanf("%d",&num)!=EOF){
   printf("%d\n",sieve(num));
  }
  return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int data=1,i,j,s[1000000],x;

	while((scanf("%d\n",&data)) != EOF)
	{
		for(i=0;i<=data;i++){
			s[i]=1;}
		x=0;
		if(data<=1){
			printf("%d\n",0);}
		else
		{
			for(i=2;i<=data/2;i++)
				for(j=i*2;j<data;j+=i)
				    s[j]=0;		
		for(i=0;i<data;i++)
			x+=s[i];
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include <cstdio>

using namespace std;

int main() {
    long NUM = 1000000;
    long n;
	long counter = 0;
	bool primeNum[NUM + 10];

	long i, ii, j, len = NUM + 10;
	
	primeNum[0] = primeNum[1] = false;
	for (i = 2; i < len; i++) primeNum[i] = true;
	
	ii = 4;
    for(i = 2; ii < NUM;) {
        if (primeNum[i]) {
            for (j = ii; j < NUM; j += i) {
                primeNum[j] = false;
            }
        }
        
        i++;
        ii = i * i;
    }
    
    while (scanf("%ld", &n) != EOF) {
        counter = 0;
        
        for (i = 0; i <= n; i++) {
            if (primeNum[i]) counter++;
        }
        
        printf("%ld\n", counter);
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
bool primes[1000000];
void Sieve(){
    for(int i = 2; i < 1000000; i++) {
      primes[i] = true;
    }//全部素数とする
    primes[0] = primes[1] = false;//0,1は素数ではない
    
    for(int i = 2; i < 1000000; i++){
            for(int j = 2 * i; j < 1000000; j += i){
                primes[j]=false;
            }
        
            
        }
    
}
int main(void){
    int n, count;
    Sieve();
    while(cin>>n){
        count = 0;
        for(int k = 2; k <= n; k++){
            if(primes[k]) count++;
        }
        cout<<count<<endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;
	bool prime[1000000] = {false};
	prime[1] = true; //1???????????\
	
	while(cin >> n){
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

C++: #include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

bool isPrime[1000000];

void setIsPrime(int x) {
    isPrime[1] = true;
	for(int i = 1; i < x; i++) {
		int n = (int)sqrt(i);
		int yakusu = 0;
		for(int j = 1; j<=n; j++) {
			if(i%j==0) yakusu++;
			if(yakusu > 2) break;
		}
		if (yakusu==1) {
			isPrime[i] = true;
		}
	}
}

int numPrimes(int x) {
    int cnt = 0;
    for (int n=1; n <= x; n++) {
        if (isPrime[n]) cnt++;
    }
    return cnt - 1;
}

int main(){
    int x;
    setIsPrime(1000000);
	while(cin >> x) {
		cout << numPrimes(x) << endl;
	}
    return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n,ans;

int main(){
    int N=1000000;
    int prime[N];
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
    while(cin>>n){
        ans=0;
        rep(i,n+1)ans+=prime[i];
        out(ans);
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
			flag=false;
			break;//素数でない時点で打ち切り
			}
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		if(flag)cnt++;
		sosu[i]=cnt;		
	}
	//for(int i=0;i<31;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int x,prime=0,count=0;
    
    cin >> x;
    
    for (int j=1; j<=x; j++)
    {
        for (int i=1; i<=x; i++)
        {
            if(j%i==0)
              count+=1;
        }
        if (count==2)
           prime+=1;
        
        count=0;
    }
    
     cout << prime;  
        
    return 0;    
}