Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include <iostream>
using namespace std;
int n;
#define MAX_N 1000000

int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数

// n以下の素数の数を返す
int sieve(int n) {
    int p = 0;
    for(int i=0;i<=n;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i=2; i<=n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for(int j=2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

main() {
    sieve(MAX_N);
    cin>>n;
    int ans=0;
    for(int i=2;i<=n;i++) {
        if(is_prime[i]) ans++;
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
 
using namespace std;
 
int main(){
    int n;
    int count = 0;
    while(cin >> n){
        count = 0;
        for(int i = 2; i <= n; i++){
            for(int j = 2; j <= i; j++){
                if(i - j > 0) if(i % j == 0) break;
                i - j || i % j || count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

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

const int MAX_N = 999999;
bool prime[MAX_N + 1];

void sieve()
{
  prime[0] = prime[1] = false;
  for(int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  for(int i = 2; i <= MAX_N; ++i)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
}

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n, i;
  int ans = 0;
  sieve();
  while(cin >> n){
    for(i = 0; i < n; i++){
      if(is_prime(i)){
	ans++;
      }
    }
    if(i == n - 1){
      break;
    }
  }
  printf("%d\n", ans);
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[1000000];
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	for(long i=2;i<1000L;i+=1L){
		for(long j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}
	long n;
	while(cin>>n){
		long cnt=0;
		rep(i,n+1){
			if(prime[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)

int main()
{
	int n;
	int c;

	while(cin >> n) {
		c = 0;

		vector<int> P(n);
		REP(i, n) P[i] = 1;

		P[0] = 0;

		for(int i = 1; i * i < n; ++i) {
			if(P[i] == 1) {
				for(int j = i + 1; j * (i + 1) - 1 < n; ++j) {
					P[j * (i + 1) - 1] = 0;
				}
			}
		}

		REP(i, n) {
			if(P[i] == 1)
				++c;
		}

		cout << c << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
//	vector<int> isPrime;
	bool isPrime[1000000];
	
	while(cin>>n)
	{
		for(int i = 0; i < n; i++){
//			isPrime.push_back(1);
			isPrime[i] = 1;
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin <= head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
		//		cout << "+"<<i << endl;
			}
		}
		printf("%d\n",cont);
	}
}

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

int ans ;
int N ;
bool prime[1000200] ;

void SE ( ) ;

int main ( ) 
{
	memset ( prime , false , sizeof ( prime ) ) ;
	SE ( ) ;
	while ( scanf ( "%d" , &N ) == 1 ) {
		ans = 0 ;
		if ( N >= 2 ) {
			ans++ ;
		}
		for ( int i = 3 ; i <= N ; i += 2 ) {
			if ( prime[i] == false ) {
				ans++ ;
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

void SE ( )
{
	prime[0] = prime[1] = true ;
	for ( int i = 3 ; i < 1004 ; i += 2 ) {
		if ( prime[i] == false ) {
			for ( int j = i * i ; j < 1000200 ; j += i * 2 ) {
				prime[j] = true ;
			}
		}
	}
}

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

int whether(int num);
int count(int num);

int main(){
	int n;
	int a;

	while(1){
		if(feof(stdin)==EOF) break;
		scanf("%d",&n);
		a = count(n);
		printf("%d\n",a); 
	}

	return 0;
}

int whether(int num){
	int s=sqrt(num);
	int i;
	for(i=3; i<=s; i+=2){ if(num%i==0) return 0; }

	return 1;
}

int count(int num){
	int a=1;
	int i;
	if(num <2){ return 0; }
	for(i=3; i<=num; i+=2){
		a += whether(i);
	}

	return a;
}

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

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList,primeList;
		for(int i=2;i<=NUM;++i){
			numList.push_back(i);
		}
		for(int i=numList.front();i*i<NUM;i=numList.front()){
			primeList.push_back(i);
			numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
		}
		int cnt=numList.size()+primeList.size();	
		std::cout << cnt << std::endl;
		}
	return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
	int i;
	int pos;
	int val;
	int target;
	int sosuList[78499];

	memset(sosuList, 0, sizeof(sosuList));

	sosuList[0] = 2;
	sosuList[1] = 3;
	sosuList[2] = 5;
	sosuList[3] = 7;
	sosuList[4] = 11;

	while (cin >> target) {
		for (pos = 0; sosuList[pos] != 0; pos++) {
			if (sosuList[pos] > target) break;
		}
		for (val = sosuList[pos - 1] + 1 ; val <= target ; val++) {
			for (i = 0; i < pos - 1 ; i++) {
				if (sosuList[i] * 2 > val) { i = pos; break; }
				if (val % sosuList[i] == 0) break;
			}
			if (i >= pos - 1) sosuList[pos++] = val;
		}
		cout << pos << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

bool isprime[1000000];

void solve(int n) {
    int cnt = 0;
    for (int i = 2; i <= n ; ++i) {
        if(isprime[i]) {
            cnt++;
            for (int j = i*2; j <=n ; j = j + i) {
                isprime[j] = false;
            }
        }
    }
    cout << cnt << endl;
}

int main() {
    int n;
    while(cin>>n) {
        for (int i = 0; i <= n; ++i) {
            isprime[i] = true;
        }
        isprime[0] = isprime[1] = false;
        solve(n);
    }


    return 0;
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int list[100000];

    cnt=0;
    for (long i=2; i<1000000; i++){
	//    printf("%d %d\n",i, cnt);
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
	printf("input : ");
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (long i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;

    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}