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>
using namespace std;

int main()
{
	int n[30];
	int i = 0;
	while(cin >> n[i]) {i++;}
		
	for (int k = 0;k < i;k++){
		int s = 0;
		for (int j = 2;j <= n[k];j++){
			int yaku = 0;
			for (int m = 1;m <= j / 2;m++){
				if (j % m == 0){yaku++;}
			}
			if (yaku == 1){s++;}
		}
		cout << s << endl;
	}	
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isprime (int n){

	if (n == 0 || n == 1){
		return false;
	}else if (n == 2){
		return true;
	}else if (n % 2 == 0){
		return false;
	} // end if
	
	for (int i = 3; i <= sqrt(n); i+= 2){
		if (n % i == 0){
			return false;
		} // end if
	} // end for
		
	return true;
}

int main()
{
	
//	cut here before submit 
//	freopen("testcase.prime", "r", stdin);
	string str = "";
	vector <int> prime(1000000, 0);

	int count = 0;
	for (int i = 2; i < 1000000; ++i){
		if (isprime(i)){
			++count;
		} // end if
		prime[i] = count;
	} // end for	

	while (getline (cin, str )){
		int n = 0;
		stringstream ssn(str);
		ssn >> n;
		cout << prime[n] << endl; 
	} // end while

	return 0;
}

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

int main()
{
    int prime[MAX-1], S[MAX-1];
    for (int i = 0; i < MAX; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++)
    {
        if (prime[i] != 0)
        {
            for (int j = 2 * i; j < MAX; j += i)
            {
                prime[j] = 0;
            } } }
        
        
    for (int i = 1; i < MAX; i++)
    {
        S[i] = prime[i] + S[i - 1];
    }
    S[0] = prime[0];
    int N;
    while (cin >> N)
    {
        cout << S[N] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

using namespace std;

int main()
{
	int p[10000];
	int c=0,flag,n;
	long long ans;

	p[c++]=2;p[c++]=3;p[c++]=5;

	for(int i=7;i*i<999999;i++){
		flag=1;
		for(int j=0;j<c;j++){
			if(i%p[j]==0){flag=0;break;}
		}
		if(flag) p[c++]=i;
	}

	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(int i=0;p[i]<=n;i++) ans++;
		cout<<ans<<endl;
	}


	return 0;
}

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

int solve(int n) {
	vector<bool> v;
	vector<int> prime;
	if (n == 0)return 0;
	else if (n == 1)return 0;
	else if (n == 2)return 1;
	else {
		v.push_back(false);//0
		v.push_back(false);//1
		for (int i = 2; i <= n; i++) {
			v.push_back(true);
		}
		for (int i = 2; i <= (int)pow(n, 0.5) + 1; i++) {
			if (v[i] == true) {
				for (int j = i * 2; j <= n; j += i) {
					v[j] = false;
				}
			}
		}
		//cout << "v.size()=" << v.size() << endl;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == true) {
				prime.push_back(i);
			}
		}
		return prime.size();
	}

}

int main()
{
	int n;
	while (cin >> n) {
		int ans = solve(n);
		cout << ans << endl;
	}

    return 0;
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int prime[INF];
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;

  REP(i, INF) prime[i] = 1;

  prime[0] = prime[1] = 0;

  for (int i =  2; i * i <= INF; i++){
    if (prime[i]){
      for (int j = 2; i * j <= INF; j++){
        prime[i * j] = 0;
      }
    }
  }

  while (cin >> n, n){
    int ct = 0;
    for (int i = 2; i <= n; i++){
      if (prime[i]) ct++;
    }
    cout << ct << endl;
  }
}

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


int main() {

//変数の宣言

	int i,n,j,sum,judge=1;
	
	while(cin>>n){
		sum = 1;
		for(i=3;i<n+1;i+=2){
			for(j=3;j<=sqrt(i);j+=2){
				if(i%j==0){
					judge = 0;
					break;
				}
			}
			if (judge==1){
				sum++;
			}
			judge = 1;
		}
		
		cout << sum <<endl;
	}

	return 0;
}

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

vector<int>memo;

bool isprime(int q){
	if(q==2){
		return true;
	}else if(q%2==0){
		return false;
	}else{
		int max=sqrt(q);
		for(int i=3;i<q;i=i+2){
			if(q%i==0)return false;
		}
		return true;
	}
}

int main(){
	int n;
	while(cin>>n){
		if(n+1>memo.size())memo.resize(n+1);
		int sum=0;
		for(int i=2;i<=n;i++){
			if(memo[i]==1){
				sum++;
				continue;
			}else if(memo[i]==-1){
				continue;
			}else if(isprime(i)){
				sum++;
				memo[i]=1;
			}else{
				memo[i]=-1;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

const int m=500000;
int prime[m];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<m; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<m; j+=i) prime[j]=0;
    }
    for(int i=1; i<m; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        if(n<2) cout<<"0\n";
        else cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}

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

int main(){

	int n, i, j, prmnum;
	bool prm = true;
	while(cin>>n){
		prmnum = 1;

		for( i=3;i<=n;i+=2 ){
			prm = true;

			for( j=3;j<=sqrt((double)i);j+=2 ){
				if( i%j == 0 ){
					prm = false;
					break;
				}
			}


			if(prm)prmnum++;
		}


		cout << prmnum << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define MAX_LIST 1000000

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	int n;
	cin>>n;
	int count=0;
	for(int i=0;i<=n;i++){
		if(prime[i]==1){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

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

int main(){
	int n,s,a;
	
	while(cin >> n){
		a=1;
		for(int j=3;j<=n;j+=2){
			s=0;
			for(int i=3;i<j;i+=2){
				if(j%i==0){
					s=1;
					break;
				}
			}
			if(s==0){
				a++;
			}
		}
		cout << a << "\n";
	}
		
	
return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){

	int i, j, k;
	int n;

	while(cin >> n){

		int count = 0;

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

	}


	return 0;
}