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<stdio.h>
#include<math.h>
#include<string>
using namespace std;

int main(){
  int n,i,j;
  while(cin >> n) {
    if(n==1){
      cout << 0 <<endl;
      continue;
    }
    int k = 0, a[n];
    a[0] = 2;
  
    for (i = 3; i <= n; i = i + 2) {
      for (j = 0; j <= k; j++) {
        if(i % a[j] == 0 ) break;
        if(i <= a[j] * a[j]) {
          k++;
          a[k] =i;
          break;
        }
        
      }
      if(j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    cout << k+1 << endl;
  }
  
  return 0;
}

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

int main()
{
	int n = 0, x = 0;
	int countdata[1000];
	while (cin >> n) {
		int count = 0;
		for (int a = 2; a <= n; a++) {
			if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a % 7 != 0) 
				count++;
			if (a == 2 || a == 3 || a == 5 || a == 7)
				count++;
		}
		countdata[x] = count;
		x++;
	}
	for (int a = 0; a < x; a++) {
		cout << countdata[a] << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int ma=1e7;
  vector<bool>sosu(ma,1);
  sosu[0]=sosu[1]=0;
  for(int i=4;i<ma;i+=2)sosu[i]=0;
  for(int i=3;i<ma;i+=2)
    for(int j=i*3;j<ma;j+=i*2)sosu[j]=0;
  int in;
  while(cin>>in){
    int co=0;
    loop(i,2,in+1)if(sosu[i])co++;
    cout<<co<<endl;
  }
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,prime[1000000]={0};
  int count=0;
  while(cin>>n/*入力（EOF）*/){
    for(int i=2/*0と１は素数ではないため２から始める。*/;i<=sqrt(n)/*ルートn*/;i++){
      for(int j=i*2/*i*2は必ず素数ではない*/;j<=n;j+=i/*j<=nまでi*aをする。*/){
	prime[j]=1;/*jは素数ではない。*/
      }
    }
    for(int i=2;i<=n;i++){
      if(prime[i]==0){/*もし素数だったら*/
	count++;
      }
    }
  cout<<count<<endl;
  count=0;
  }
  return 0;
}

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

int main()
{
	int n;
	int i,j,count,flag,temp;
	while(cin>>n)
	{
		count = 0;
		for(i = 3;i <= n;i++)
		{
			flag = 0;
			temp = sqrt(i);
			for(j = 2;j<=temp;j++)
			{
				if(i%j==0)
				{
					flag = 1;
					break;
				}
			}
			if(flag!=1)
				count++;
		}
		cout<<count+1<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>

using namespace std;

int main(void){
	
	int i, j, n, count = 0;
	bool arr[999999] = {false};

	while (cin >> n) {

		for (i = 2; i <= n; i++) {
			arr[i] = true;
		}

		for (i = 2; i <= sqrt(n); i++) {
			if(arr[i])
				for (j = 0; i*(j + 2) <= n; j++) {
					arr[i*(j + 2)] = false;
				}
		}

		for (i = 2; i <= n; i++) {
			if (arr[i] == true)
				count++;
		}

		cout << count << endl;
		count = 0;

	}

	return 0;
}

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


int main() {

//変数の宣言

	int i,n,j;
	
	while(cin>>n){
		vector<int> prime;
		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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
#define MAX 1000000
bool sosu[MAX]={false};
int main(){
  for(int i=3;i<MAX;i+=2){
    if(sosu[i])continue;
    for(int j=i*3;j<MAX;j+=i*2)
      sosu[j]=true;
  }
  for(int i=4;i<MAX;i+=2)
    sosu[i]=true;
  int in;
  while(cin>>in){
    int co=0;
    loop(i,2,in+1)if(!sosu[i])co++;
    cout<<co<<endl;
  }


}

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

typedef long long ll;


vector<ll> is_prime(999999+1,true);

void init_prime() {
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=999999; i++) {
	if(is_prime[i]) {
	    for(int j=i*2; j<=999999; j+=i)
		is_prime[j] = false;
	}
    }
}

int table[1000000] = {0};

int main() {

    init_prime();

    for(int i=1; i<1000000; i++) {
	if(is_prime[i]) 
	    table[i] = table[i-1]+1;
	else
	    table[i] = table[i-1];

    }
    
    
    int a;
    
    while(cin >> a) {
	cout << table[a] << endl;
	
    }


    return 0;
}

C++: #include <cstdio>
#include <vector>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		vector<int> prime;
		
		if (n >= 2){
			prime.push_back(2);
		}
		for (int i = 3; i <= n; i++){
			int j;
			for (j = 0; j < prime.size(); j++){
				if (i % prime[j] == 0){
					break;
				}
			}
			if (j == prime.size()){
				prime.push_back(i);
			}
		}
		printf("%d\n", prime.size());
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

    for (int i = 2; i < 1000000; i += 1 + (i & 1)) {
        if (!a[i]) continue;
        for (int j = i*2; j < 1000000; j += i) a[j] = false;
    }

    int n;
    while (~scanf("%d", &n)) {
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define MAXN 999999
using namespace std;
bool is_prime[MAXN];
int prime[MAXN];
int main()
{
    int p=0;
    for(int i=0;i<=MAXN;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=MAXN;i++)
        if(is_prime[i])
    {
        prime[p++]=i;
        for(int j=2*i;j<=MAXN;j+=i) is_prime[j]=false;
    }
    int n,x;
    while(scanf("%d",&n)!=EOF)
    {
      x=lower_bound(prime,prime+p,n)-prime;
      if(prime[x]==n) printf("%d\n",x+1); else printf("%d\n",x);
    }
    return 0;
}