Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

using namespace std;

#define N 100000

int main(){

    bool primes[N];
    int  n; 

    fill(primes, primes + N, true);
    primes[0] = false;
    primes[1] = false;
    
    for(int i = 2; i < N; ++i){
        if(primes[i]){
            for(int j = i + i; j < N; j += i)primes[j] = false;
        }
    }

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

C++: #include<iostream>
using namespace std;
int main() {
	int n,ans;
	while (cin >> n) {
		ans = 0;
		for (int i = 2; i <= n; i++) {
			if (i != 2) {
				if (i % 2 == 0) {
					goto a;
				}
			}
			else {
				ans = ans + 1;
				goto a;
			}
			for (int z = 2; z <= i/2+1; z++) {
				if(i!=z){
					if (i%z == 0) {
						goto a;

					}
				}
			}
			ans = ans + 1;
		a:;
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#define MAX 1000000

int main(){
	int n;
	bool c[MAX]={true};
	int t[MAX];t[0] = 0;
	for(int i = 2;i < MAX;i++){
		for(int j = i;i*j < MAX;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < MAX;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    long cnt;
    bool flag;

    while (cin >> n) {
        if (n < 2) {
            cout << "0\n";
            continue;
        }
        else if (n == 2) {
            cout << "1\n";
            continue;
        }
        else if (n == 3) {
            cout << "2\n";
            continue;
        }
        
        cnt = 4;
        for (int i = 5; i <= n; i += 2) {
            flag = false;
            for (int j = 3; j < n; j += 2) {
                if (!(i % j)) {
                    flag = true;
                    break;
                }
            }
            if (!flag)
                cnt++;
        }
        cout << cnt << endl;
    }
    
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

int const N = 1000010;
int ans[N];

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

int main(int argc, char ** argv) {
    ans[0] = ans[1] = 0;
    for (int i = 2; i < N; ++i) {
        if (isprime(i)) ans[i] = ans[i - 1] + 1;
        else ans[i] = ans[i - 1];
    }
    int n;
    while (~scanf("%d\n", &n)){
        printf("%d\n",ans[n]);
    }
}

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

int isPrime(int a){
	int i;     
	int isTrue;     
	for(i = 3, isTrue = 1; i < a; i+=2){ 
		if( !(a%i) ){ isTrue = 0; break; } 
	}     
	return a==2||isTrue&&a%2; 
}   

int main(){
	int n,ans=0;
	while(cin >> n){
		for(int i = 2; i <= n; i++){
			if(isPrime(i))ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: import math

def check_prime(goal):
    true_or_false=False
    for i in range(2,int(math.sqrt(goal))+1):
        if goal%i==0:
             true_or_false=True
    if true_or_false==False:
        return True
    else:
        return False
anss=[]
while True:
    try:
        num=int(input())
        num_of_prime=0
        for i in range(2,num+1):
           if check_prime(i):
               num_of_prime+=1
        anss.append(num_of_prime)
    except:
        break

for ans in anss:
    print(ans)

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

bool p[1000000];

int main()
{
  for(int i=2;i*i<1000000;i++)if(!p[i])for(int j=i+i;j<1000000;j+=i)p[j]=1;
  p[0]=p[1]=1;
  int n;
  while(cin>>n){
    int ans=0;
    rep(i,n)if(!p[i])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <cstring>

bool nArray[999999];

int main() {
    int n = 0;
    for (int cou = 0; ((scanf("%d", &n) != EOF) && (cou < 30)); ++cou) {
        for (int i = 0; i < 999999; ++i) {
            nArray[i] = (i <= 1) ? false : true;
        }

        int maxValue = sqrt(n);
        for (int i = 2; i <= n + 1; ++i) {
            if (!nArray[i]) {
                continue;
            }

            for (int j = 2; (i * j) <= n; ++j) {
                nArray[i * j] = false;
            }
        }

        int result = 0;
        for (int i = 0; i <= n; ++i) {
            if (nArray[i]) {
                result++;

            }
        }

        printf("%d\n", result);
    }

    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 <iostream>
#include <vector>
using namespace std;


int main() {

//変数の宣言

	vector<int> prime;
	int i,n,j;
	
	cin >> n;
	prime.push_back(2);
	
	for(i=3;i<n+1;i++){
		for(j=0;j<prime.size();j++){
			if (i%prime[j]==0) break;
			if (j==prime.size()-1) {
				prime.push_back(i);
			}
		}
	}
	
	/*
	for(i=0;i<prime.size();i++){
		cout << prime[i] <<endl;
	}
	*/
	cout << prime.size() <<endl;
	

	return 0;
}

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

int main() {
  vector<bool> isPrime(MAX, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i * i < MAX; i++) {
    if (isPrime[i]) {
      for (int j = 2; i * j < MAX; j++) {
        isPrime[i * j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int ans,n,i,k;
	while(1){
		ans=0;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			cout<<0<<endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=9){
				for(i=9;i<=n;i+=2){
				    int prime=1;
				    for(k=3;k<=sqrt(i);k+=2){
					    if(k==3||k%3!=0){
					        if(i%k==0){
						            prime=0;
						            break;
					        }
    					}
					}
				    if(prime)ans++;
				}
			}
		cout<<ans<<endl;
		}
	}
}