Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		flag := false
		count := 0

		for i := 2; i <= num; i++ { //1を除く入力値以下の数字
			for j := 2; j < i-1; j++ {
				if i%j == 0 && j != 1 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

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

signed main(){
  int n;
  while(cin>>n&&n){
    if(n==1){cout<<0<<en; RE;}
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)) ans++;
    }
    cout<<ans<<en;
  }
}

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; ++i)
	{
		Counter = Counter + CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (!IsPrime(N))
		return 0;

	return 1;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????


	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}