Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [40]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

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 <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int isprime(int x){
    int a[x],b=0;
    for(int i=0;i<x;i++){
        a[i]=i+1;
    }
    for(int i=0;i<x;i++){
        if(a[i]==2||a[i]==3) b++;
        if(a[i]<5||a[i]%2==0||a[i]%3==0)goto exit;
    else{
        int j=5;
        while(j<sqrt(x)){
            if(a[i]%j==0)goto exit;
            j = j+2;
        }
        b++;
    }
    exit:;
}
    return b;
}
int main() {
    int n;
    while(cin >> n){
        cout << isprime(n) << endl;
        }
    }

C++: #include<iostream>
using namespace std;
int main(){
    int X,ans,count;
    bool num[1000001]={};
    for(int i=2;i<=1000000;i++){
        if(!num[i]) 
        for(int j=i*2;j<=1000000;j+=i)  num[j] = true;
    }
    while(cin >> X)
    {
        count = 0;
        for(int i=2;i<=X;i++){
            if(!num[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

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

int main(){

  vector<int> prime(MAX,1);
  vector<int> ans;
  
  prime[0] = 0;
  prime[1] = 0;
  prime[2] = 1;
	
  for(int i=4;i<MAX;i+=2)
	prime[i] = 0;
	
  for(int i=3;i<sqrt(MAX);i+=2)
	for(int j=i+i;j<MAX;j+=i)
	  prime[j] = 0;
  
  int n;
  
  while(cin>>n){
	int cnt = 0;
	for(int i=0;i<=n;++i)
	  if(prime[i]==1)
		cnt++;
	cout<<cnt<<endl;
  }
	
  return 0;
  
}

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

#define M 1000001

int main(void)
{
    int x, i, j;
    int p[M];
    
    for (i = 0; i < M; i++) {
        p[i] = 1;
    }
    p[0] = p[1] = 0;
    for (i = 2; i * i < M; i++) {
        if (p[i] == 1) {
            for (j = i * i; j < M; j += i) {
                p[j] = 0; 
            }
        }
    } 
    for (i = 0; i < M-1; i++) {
        p[i+1] += p[i];
    }
    while (scanf("%d", &x) != EOF) {
        printf("%d\n", p[x]);
    } 
    return (0);
}

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;
}