Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	a, _ := strconv.Atoi(scanner.Text())
	return a
}

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return true
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    sieve();
    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i=2; i<=n; ++i) {
            if (prime[i]) {
                cnt ++;
            }
        }
        cout << cnt << "\n";
    }
    return 0;
}

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

int main(){

	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];
	
	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}
	
	while(true){
	int n;
	cin>>n;
	
	if(cin.eof())
		break;
	
	cout<<n_prime[n]<<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0,k;
	while(k<30){
		cin >> N;
		count = 0;
		if(N<0)	break;
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
		k++;
	}
	return 0;
}

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

#define Max 1000000

int isPrime[Max];

int main(){
    int num;
    int i,j;

    //配列の初期化
    isPrime[0] = isPrime[1] = 0;
    for(i = 2; i < Max; ++i){
        isPrime[i] = 1;
    }

    for(i = 2; i < Max; i++){
        if(isPrime[i] == 1){
            if(i % 2 == 0){
                isPrime[i] = 0;
            }else if(i % 3 == 0){
                isPrime[i] = 0;
            }else if(i % 5 == 0){
                isPrime[i] = 0;
            }else if(i % 7 == 0){
                isPrime[i] = 0;
            }
        }
    }

    isPrime[2] = 1;isPrime[3] = 1;isPrime[5] = 1;isPrime[7] = 1;

    while(cin >> num){
        int count = 0;
        for(i = 2; i <= num; ++i){
            if(isPrime[i] == 1){
                count++;
            }
        }
        cout << count << endl;
    }

}

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

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[999999];
  int num;
  int nump=0;
  int cnt=0;

	while(scanf("%d",&num)!=EOF){
	  set_prime_number(prime_number,num);
	 for (int i = 0; i < num; i++) {
		 if (prime_number[i]){cnt++;}
	 }
	 printf("%d",cnt);
	 cnt=0;
	}


  return 0;
}

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

using namespace std;

int A[1000000];
int Eratosthenes(int n)
{
	int mama = 0;
	for (int i = 0; i < n; i++)
	{
		A[i] = 1;
	}
	for (int i = 2; i < sqrt(n); i++)
	{
		if (A[i])
		{
			for (int j = 0; i*(j + 2) < n; j++)
			{
				A[i*(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < n; i++)
	{
		if (A[i])
		{
			mama++;
		}
	}
	return mama;
}

int main()
{
	int n;

	while ((scanf("%d",&n))!= -1)
	{
		printf("%d\n", Eratosthenes(n+1));
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()

{

              int get_num,min_remainder=1,remainder,index=2;

              cout << "整数を入力してください" << endl;

              cin >> get_num;

              if(get_num == 1)

              {

                            min_remainder=0;

              }

              if(get_num > 2 && get_num%2 == 0)

              {

                            min_remainder=0;

              }

              while(index*index <= get_num)

              {

                  remainder = get_num%index;

                  if(remainder < min_remainder)

                  {

                      min_remainder=0;

                  }

                  index++;

              }

              if(min_remainder !=0)

              {

                  cout << get_num << "は素数です" << endl;

              }

              else

              {

            cout << get_num << "は素数ではありません" << endl;

             }

}

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

int main()
{
    const int NUM_OF_INPUT = 30;

    for(int k=0; k<NUM_OF_INPUT; k++)
    {
        long long limit;

        cin >> limit;

        long long count = 0;
        int p = 2, i, j;
        bool isPrime[limit];

        for(i=0; i<limit; i++)
        {
            isPrime[i] = true;
        }

        for(i=p-1; i<limit; )
        {
            for(j=2; (p * j) <=limit; j++)
            {
                isPrime[(p * j) - 1] = false;
            }

            while(++i < limit)
            {
                if(isPrime[i])
                {
                    p = i + 1;
                    break;
                }
            }
        }

        for(i=1; i<limit; i++)
        {
            count = (isPrime[i] ? count + 1 : count);
        }

        cout << count;
    }

    return 0;
}

C++: #include<iostream>

typedef int moe;
typedef long lolita;
typedef char cuffs;
typedef float frill;
typedef double ruffle;
typedef void voile;
typedef unsigned tasogare;

#define katyusya const
#define apron volatile
#define pleats static
#define fancy virtual

using namespace std;

#define YUU 1000000

voile make_prime(moe n_prime[]){
  pleats moe is_prime[YUU];

  for( moe ai = 0; ai < YUU; ++ai )
    is_prime[ai] = 1;

  is_prime[0] = 0;
  is_prime[1] = 1;
  is_prime[2] = 1;

  for( moe ai = 2; ai < YUU; ++ai )
    if( is_prime[ ai ] )
      for( moe mai = 2; ai * mai < YUU; ++mai)
	is_prime[ ai * mai ] = 0;

  for( moe ai = 0; ai < YUU; ++ai )
    n_prime[ ai ] = 0;

  for( moe ai = 2; ai < YUU; ++ai ){
    n_prime[ ai ] = n_prime[ ai - 1 ];
    if( is_prime[ ai ] )
      n_prime[ ai ]++;
  }
}

moe main(){
  tasogare yuu;
  pleats moe n_prime[YUU];

  make_prime( n_prime );
  while(true){
    cin >> yuu;
    if( yuu == 0 || cin.eof() ) break;
    cout << n_prime[ yuu ] << endl;
  }

  return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
    long long n;

    while (scanf("%lld", &n) != EOF){
        int cnt = 0;
        for (long long i = n; i >= 2 ; i--){
            for (long long j = 2; j < i; j++){
                if (i % j == 0){
                    //printf("%d\n", i);
                    cnt++;
                    break;
                }
            }
        }
        printf("%d\n", n - 1 - cnt);
    }

    return (0);
}

C++: #include <iostream>

using namespace std;

int main() {
	int num=0,y=0, n;
	while(cin>>n){
		for(int i=2; i<=n; i++){
			y = 0;
			for(int j=2; j<i; j++){
				if(i%j==0){ y++;}
			}
			if(y==0){ num++; }
		}
		cout<<num<<endl;
	}
	return 0;
}

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

vector<int> sieve;

void make_prime(){
  bool a[1000001];
  for(int i = 0; i < 1e6; i++)a[i] = false;
  a[0] = true;
  a[1] = true;
  for(int i = 2; i <= 1e6; i++){
    if(a[i])continue;
    sieve.push_back(i);
    for(int j = i; j <= 1e6; j += i){
      a[j] = true;
    }
  }
}

int main(){
  int n;
  make_prime();
  while(cin >> n){
    int cnt = 0;
    for(int i = 0; sieve[i] <= n; i++)cnt++;
    cout << cnt << endl;
  }
}