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

C++: #include <iostream>
#include<algorithm>
using namespace std;
#define MAX 10000000
bool prime[MAX]={true};

int countPrime(int n){
	if(n<2) return 0;
	if(n==2) return 1;
	int ret=0;
	// fill(data, data + numof(data), 0);
	fill(prime, prime+MAX,true);
	for(int i=2;i*i<=n;i++){
		if(prime[i]){
			for(int j=i*i;j<=n;j=j+i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=n;i++){
		if(prime[i]) ret++;
	}
	return ret;
}

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

C++: #include<iostream>
#include<cmath>
#define FOR(x,s,g) for(int x=(s);x<=(g);x++)
using namespace std;

int main(){
  int n;
  while(cin>>n){
    int count=0;
    FOR(i,2,n){
      bool flag=false;
      FOR(j,2,sqrt(i)){
	if(i%j==0){
	  flag=true;
	  break;
	}
      }
      if(!flag) count++; 
    }
    cout<<count<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
// エラトステネスのふるい
int main() {
  int num = 1000000;
  int n, prime[num];
  while (cin >> n) {
    for (int i = 0; i < num; i++) {
      prime[i] = 0;
    }
    prime[0] = 1;
    prime[1] = 1;
    
    int count = 0;
    for (int i = 0; i <= n; i++) {
      if (prime[i] == 0) {
	count++;
	for (int j = i; j <= n; j += i) {
	  prime[j] = 1;
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n=0,K=0;
	while(cin>>n){
		for(int i=2;i<=n;i++){
			int c=0;
			for(int x=2;x<i;x++){
				if(i%x==0){
					c=c;
				}
				else{
					c++;
				}
			}
			if(c==i-2){
				K++;
			}
		}
		cout<<K;
		K=0;
	}
}

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

using namespace std;

#define N 1000000

int main(){

    bool primes[N];
    int  n; 

    fill(primes, primes + (sizeof primes / sizeof *primes), true);
   
    primes[0] = false;
    primes[1] = false;
    
    for(int i = 2; i + i <= N; ++i){
        if(primes[i]){
            for(int j = i + i; j < N; j += i)primes[j] = false;
        }
    }

    while(cin >> n){
        int  count = 0;
        for(int i = 2; i <= n; ++i){
            if(primes[i])count++;
        }
        cout << count << endl;
    }
    
	return 0;
}

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

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

	//cout << "数字を入力してください" << endl << "number :";
	cin >> num;

	for(i=2; i<num; i++){
		for(j=2; j<i; j++){
			if(i%j ==0){
				break;
			}
		}
		if(j == i){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

static const long MAX = 1000000L;
 
int main() {
    vector<long> prime;
    bool isPrime;
    long n;
 
    long i, len = sqrt(MAX) + 1;
    long j, lenJ;
    long k;
     
    prime.push_back(2);

    for (i = 3; i <= len; i += 2) {
        isPrime = true;
        lenJ = prime.size();
        k = sqrt(i) + 1;
        for (j = 0; j < lenJ; j++) {
            if (k <= prime[j]) break;

            if (i % prime[j] == 0) {
                isPrime = false;

                break;
            }

        if (isPrime) prime.push_back(i);
    }

    lenJ = prime.size();
     
    while (cin >> n) {
        counter = 1;

        if (n < 2) counter = 0;
         
        for (i = 3; i <= n; i += 2) {
            isPrime = true;

            k = sqrt(i) + 1;
            for (j = 0; j < lenJ; j++) {
                if (k <= prime[j]) break;

                if (i % prime[j] == 0) {
                    isPrime = false;

                    break;
                }
            }

            if (isPrime) counter++;
        }
         
        cout << counter << endl;
    }
 
    return 0;
}

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

using namespace std;
#define MAX_NUM 999999


void do_calc(int *numPrime){
  for(int i=2;i<=MAX_NUM;i++){
    bool flag = false;

    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0){
	flag = true;
	break;
      }
    }
      
    if(flag){
      numPrime[i] = numPrime[i-1];
      continue;
    }else{
      numPrime[i] = numPrime[i-1] + 1;
    }
  }
}
  


int main(){
  int n;
  int numPrime[MAX_NUM];

  do_calc(numPrime);
  while(cin >> n){
    cout << numPrime[n] << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#define MAX 1000000
typedef long long int ll;

using namespace std;

bool isprime[MAX];
int prime[MAX];

void sieve()
{
    isprime[1]=1;
    for(int i=2;i<=sqrt(MAX);i++){
        if(!isprime[i]){
            for(int j=i*i;j<=MAX;j+=i){
                isprime[j]=true;
            }
        }
    }
    int count=0;
    for(int k=1;k<=MAX;k++){
        if(!isprime[k])prime[k]=++count;
        else prime[k]=count;
    }
}

int main()
{
    sieve();
    int n;
    while(scanf("%d",&n)==1){
        printf("%d\n",prime[n]);
    }
    return 0;
}

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

int prime[1000000];


bool isPrime(int n) {
  int x = (int)sqrt(n);
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  return 0;
}

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

int main()
{
  bool is_prime[1000000];fill(is_prime,is_prime+1000000,true);
  int count_prime[1000000];fill(count_prime,count_prime+1000000,0);
  is_prime[0]=false,is_prime[1]=false;
  for(int i=2;i<1000000;i++)
  {
    count_prime[i]=count_prime[i-1]+is_prime[i];
    if(!is_prime[i])continue;
    for(int j=i*2;j<1000000;j+=i)is_prime[j]=false;
  }
  int n;
  while(cin>>n)printf("%d\n",count_prime[n]);
}

C++: #include <iostream>

using namespace std;

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

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

#define MAX 1000000

int main(){
	bool p[MAX+1];
	int num,answer;

	while( scanf("%d" , &num) != EOF ){	
		p[0] = false;
		p[1] = false;
		for(int i=2 ; i<=MAX ; i++){
			p[i] = true;
		}
		answer = 0;

		for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
			if(p[i]==1){
				for(int j=i*2; j<=MAX; j=j+i){
					p[j] = false;
				}
			}
		}

		for(int i=0; i<=num; i++){
			if(p[i]){
				answer++;
			}
		}
		printf("%d\n", answer);
	}
}