Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

C++: #include <iostream>
#include <cmath>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	bool fl[1000001];
	memset(fl, true, sizeof(fl));
	for (int i = 2; i <= sqrt(num); i++) {
		if (fl[i]) {
			for (int j = 2; j*i <= num; j++) {
				fl[i*j] = false;
			}
		}
	}
	for (int i = 2; i <= num; i++) {
		if (fl[i]) {
			count++;
		}
	}
	return count;
}

int main() {

	int num = 0;
	while (cin >> num) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 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;
}