Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

using namespace std;


int main()
{
    unsigned int n;
    while( cin >> n )
    {
        bool *prime = new bool[n+2];
        unsigned int k, allprime = 0;

        memset( prime, false, n+2 );
        prime[2] = true;
        for( int i = 3; i <= n; i++ )
        {
            if( i % 2 == 0 )
            {
                prime[i] = false;
            }
            else
            {
                prime[i] = true;
            }
        }
        k = sqrt( n );
        for( int i = 3; i <= k; i++ )
        {
            for( int j = i + i; j <= n; j += i )
            {
                prime[j] = false;
            }
        }
        for( int i = 2; i <= n; i++ )
        {
            if( prime[i] )
            {
                allprime++;
            }
        }
        cout << allprime << '\n';
    }
    return 0;
}

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

using namespace std;

int main(){
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
	static int N,count[1000009];
		count[1] = 1;
	for(int x=3;x<=1000000;x=x+2){
		int flag = 0;
		for(int y=3;y<=sqrt(x);y=y+2){
			if((x%y)==0)	flag = 1;
		}
		count[x] = count[x-2];
		count[x-1] = count[x-2];
		if(flag == 0)	count[x]++;
	}
	count[1] = 0;
	while(cin >> N){
		cout << count[N] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    bool f[1000001];
    fill(f,f+1000001,true);
    f[0]=f[1]=false;
    for(int i=2;i*i<=1000001;i++)
        if(f[i])
            for(int j=i*i;j<=1e6;j+=i)
                f[j]=false;

    int n;
    while(cin>>n)
        cout<<count(f,f+n+1,true)<<endl;

}

C++: #include <iostream>

using namespace std;

bool is_prime(int x)
{
	if (x == 2) return true;
	if (x % 2 == 0) return false;
	for (int i = 3; i*i <= x; i += 2)
		if (x % i == 0)
			return false;

	return true;
}

int main()
{ 
	int n;

	while (cin >> n)
	{
		int cnt = 0;
		for (int i = 2; i <= n; ++i)
			cnt += is_prime(i);

		cout << cnt << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    int prime[1000000];
    int ptr = 0;

    prime[ptr++] = 2;
    prime[ptr++] = 3;

    while (cin >> n) {
        if (n == 2) {
            cout << "1\n";
            continue;
        }
        else if (n == 3) {
            cout << "2\n";
            continue;
        }

        int count = 2;        
        for (int i = 5; i <= n; i += 2) {
            bool flag = false;
            for (int j = 1; prime[j] * prime[j] <= i; j++) {
                if (!(i % prime[j])) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                prime[ptr++] = i;
                count++;
            }
        }
        cout << count << "\n";
    }
    
    return 0;
}

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

int main() {

  bool sosu[1000000] = {false};
  for ( int i = 2; i < 1000000; i++ ) {

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

  }

  int n;
  while( cin >> n ) {

    int cnt = 0;
    for ( int i = 2; i <= n; i++ ) {
      if ( sosu[i] == false ) cnt++;
    }

    cout << cnt << endl;

  }

  return 0;

}

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

using namespace std;

int main(){
	int n,i,j,buf,cnt;
	bool flag;

	while(cin >> n){
		if(n == 1){
			cout << "0" << endl;
			continue;
		}

		cnt = 1;

		for(i=3;i<=n;i+=2){
			flag = false;
			buf = (int)sqrt((double)i);

			for(j=3;j<=buf;j+=2){
				if((i % j) == 0){
					flag = true;
					break;
				}
			}

			if(flag == false;){
				cnt++;
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

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

int main()
{
	int number=0;
	int result=0;
	while(1)
	{
		result=1;
		cin>>number;
		if(number==1||number==0)
			result=0;
		else
		{

			for(int i=number;i>2;i--)
				if(i%2!=0)
				{
					int f=0;
					for(int j=2;j<=sqrt(i);j++)
						if(i%j==0)
						{
							f=1;	
							break;
						}
					if(f==0)
						result++;
				}
		}
		cout<<result<<endl;
	}
	return 0;
}

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

bool d[100000];

int main()
{
  int n;
  int ans;
  while(cin >> n)
  {
    n++;
    for(int i = 0; i < 100000; i++)
      d[i] = false;
    d[0] = d[1] = true;
    ans = 0;
    for(int i = 2; i < n; i++)
    {
      if(d[i])
        continue;
      for(int j = i + i; j < n; j+= i)
        d[j] = true;
    }
    for(int i = 0; i < n; i++)
    {
      //cout << d[i] << endl;
      ans += !d[i] ? 1 : 0;
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

long n,ans;

int main(){
	cin >> n;
	ans = 1;
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}
	if(n == 2){
		cout << 1 << endl;
		return 0;
	}
	for(int i=3;i<=n;i=i+2){
		ans += 1;
		for(int j=3;j*j<=i;j=j+2){
			int k = i/j;
			if(i == k*j){
				ans -= 1;
				break;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

C++: #include <stdio.h>

int main() {
    int i, k, v,scan,an;
    int MAX_V = 999999;
    int count[MAX_V+1];
    int prime[MAX_V+1];
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    }
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0;   
            } 
        }
    }
    count[2]=0;
    for(i=2;i<=MAX_V;i++){
        count[i+1]= count[i]+prime[i];
    }
    while(scanf("%d",&scan)!= EOF){
        printf("%d\n",count[scan+1]);
    }
    return 0; 
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>
#include <vector>
#include <algorithm>

#define MAX 999999

using namespace std;

int num_prime[MAX];
bool not_prime_flag[MAX];

int main()
{
    int n;
    int max_input;
    vector<int> input;

    while (cin>>n){
        input.push_back(n);
    }
    max_input=*max_element(input.begin(),input.end());
    for (int i = 1; i < max_input; ++i) {
        if(!not_prime_flag[i]){
            for (int j = 2; (i+1)*j-1 < max_input; ++j) {
                not_prime_flag[(i+1)*j-1] = true;
            }
        }
        num_prime[i]=num_prime[i-1]+!not_prime_flag[i];
    }
    for (int i:input) {
        cout<<num_prime[i-1]<<endl;
    }
    return 0;
}

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

using namespace std;

bool isprime(int x);

int main() { 
    int prime; 

    while( cin >> prime ) {

	int count = 0;
	
	for(int i=1;i<=prime;i++) 
		count += isprime(i);
		
    cout << count << "\n";
	}
    return 0; 
} 

bool isprime(int x) {
	
	if ( x == 2)
	return true;
	
	if( x < 2 || x % 2 == 0 )
	return false;
	
	int i = 3;
	
	while( i <= sqrt(x) ) {
		
		if( x % i == 0 )
		return false;
		i += 2;
		
	}
	return true;
}