Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

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

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: #include <stdio.h>
#include<iostream>
#include <math.h>
using namespace std;
int main() {
        int n;
        int data=0;
        while(scanf("%d",&n)!=EOF&&data<=30){
            int a[n];
            int num=0;
            for(int i=0; i<=n; i++) {
                a[i] = i;
            }
            a[1] = 0;
            for (int i=2; i<sqrt(n); i++) {
                for (int j=i+1; j<=n; j++) {
                        if (a[j]!=0 && a[j]%i==0) {
                                a[j] = 0;
                        }
                }
            }
            for(int i=2;i<=n;i++)
                if(a[i]!=0)
                    num++;
            cout<<num<<endl;
            data++;
        }
        return 0;
}

C++: #include<iostream>
#include<cassert>
#include<time.h>
#include<cmath>
using namespace std;

/**
作用：判断一个数是否是素数
参数x：待判断的素
参会primes：存储比x小的所有素数 的数组
返回：是素数返回true，否则返回false
*/
bool isPrime(int x,int *primes)
{
    for(int i=0;primes[i]*primes[i]<=x;++i) //用primes中存储的素数做为试除因子。
    {
        if(x%primes[i]==0) return false;
    }
    return true;
}


/**
作用：统计[2,n]之间的素数的个数
参数：n
返回：素数的个数
*/
int countPrimes(int n) {
    
    if(n<2) return 0;
    
    int count=0;
    int* primes = new int[(n-1)/2+1] ;
    
    if(n >=2) primes[count++] = 2;   //2是第一个素数，直接将他放入数组。

    for(int i=3;i<=n;++i)
    {
        if(isPrime(i,primes))   //如果 i为素数
        {
            primes[count++] = i; //则将 i存储到数组中
        }
    }

    delete[] primes;
    return count;

}

int main()
{
    int n;
    while (cin >> n) {
        int total = countPrimes(n);
        cout << total <<endl;
    }
    
    return 0;
}

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

int sosu( int n ) {
	int i , lim = (int)(sqrt(n));
	
	if ( n == 2 ) return 1;
	if ( n % 2 == 0 ) return 0;
	
	for ( i = 3; i <= lim; i+=2 ) {
		if ( n % i == 0 ) return 0;
	}
	return 1;
}

int main (void) {
	int n , i , count = 0;
	
	while ( scanf("%d",&n) != EOF ) {
		for ( i = 2; i <= n; i++ ) {
			if ( sosu(i) ) count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool F(int n)
{
	bool r=true;
	for(int i=2;i<n;i++)
	{
		if(n%i==0){
			r=false;
			break;
		}
	
	}	
	return r;
}

int main()
{
	int number=0;
	int result=0;
	while(1)
	{
		result=0;
		cin>>number;
		for(int i=number;i>=2;i--)
		{
			if(F(i)==true)
				result++;
		}
		cout << result <<endl;
	}
	return 0;
}

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

const int MAX_N = 10000000, sqrt_N = 1000;
bool prime[MAX_N];
int wei[1000000];

int main()
{
  int N, i, j, k;

  for (i = 1; i <= 5; i += 4){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 4 * k * k + j * j) <= N; ++k){
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 2; i <= 4; i += 2){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 3 * k * k + j * j) <= N; k += 2){
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 3; i <= sqrt_N; i += 6){
    for (j = 1; j <= 2; ++j){
      for (k = j; k <= sqrt_N && (N = 4 * k * k + i * i) <= N; k += 3){
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 5; i <= sqrt_N; ++i){
    if (prime[i]){
      for (j = i * i; j <= N; j += i * i){
        prime[j] = false;
      }
    }
  }
  prime[2] = prime[3] = true;

  for (i = 2; i < 1000000; ++i){
    wei[i] += wei[i - 1];
    if (prime[i]) wei[i]++;
  }

  while (cin >> N) cout << wei[N] << '\n';
  return 0;
}

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

typedef long long LL;
using namespace std;

const int X = 1000001;
bool Find[X];

void init(){
  for(int i=0;i<X;i++){
    Find[i] = false;
  }
  for(int i=2;i<=sqrt(X);i++){
    if(Find[i])continue;
    for(int j=i+1;j<X;j++){
      if(Find[j])continue;
      if(j%i==0)Find[j]=true;
    }
  }
}

int main(){
  init();
  int n;
  while(cin >> n){
    int answer = 0;
    for(int i=2;i<n+1;i++){
      cout << Find[i] <<endl;
      if(!Find[i])answer++;
    }
    cout << answer << endl;
  }
  return 0;
}

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

int is_prime(int n){
    int i;
    int flag = 0;
    for(i=2; i<n; i++){
        if(n%i==0) { flag=1; break; }
    }
    return (flag==1)?0:1;
}


int main(){
	int i, j, n, num = 0, count = 0;

	while(cin >> n){
		count = 0;
		for(i = 1; i <= n; i++){
			if(is_prime(i) == 1 && i != 1) count ++;
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans=0;
    vector<int> vec;
    vec.emplace_back(2);
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        vec.emplace_back(i);
      }
    }
    cout << vec.size() << endl;;
  }
  return 0;
}

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

int main(){
        int n;
        int d; //素数を入れるための添字
        bool count; //割りきれるかどうかの判定
        int number[400000]; //素数を入れておく
        number[0] = 2;
        
        
        while(cin >> n != 0){
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++)
                                if(i % number[j] == 0)
                                        count = false;
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                }
        cout << d+1 << endl;
        }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool prime(int num){
	if(num<2)return false;
	else if(num==2)return true;
	else if(num%2==0)return false;
	double sqrtNum = sqrt((double)num);
	for(int i=3;i<=num;i++){
		if(num%i==0)return false;
	}
	num=0;
	return true;
}
int main(){
	int n,count=0;
	while(cin>>n){
		for(int ii=1;ii<=n;ii++){
		count+=prime(ii);
		}
		cout<<count<<endl;
		count=0;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=1e6+5;
int pri[MAX];
bool py[MAX];
int c0=0;
void isprime()
{
	memset(py,true,sizeof(py));
	int t=sqrt(MAX);
	pri[0]=pri[1]=false;
	for(int i=2;i<=t;i++)
	{
		if(py[i])
		{
			for(int j=2*i;j<=MAX;j+=i)
			py[j]=false;
		}
	}
	for(int i=2;i<=MAX;i++)
	{
		if(py[i]) pri[c0++]=i;
	}
}
int main()
{
	c0=0;
	isprime();
	while(cin>>n)
	{
		int c=0;
		for(int i=0;i<c0;i++)
		{
			if(pri[i]<=n) {c++;continue;}
			break;
		}
		cout<<c<<endl;
	}
	return 0;
}