Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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 <iostream>
#include <cmath>
using namespace std;
void cprime(int, int&);

int main() {
	int n;
	
	while (cin >> n) {
		int count = 0;
		for (int i = 0; i < n;i++) {
			cprime(i + 1,count);
		}
		cout << count << endl;
	}
}

void cprime(int n, int& count) {
	if (n == 1) return;
	for (int i = 2; i <= sqrt(n);i++) {
		if (n % i == 0) return;
	}
	count++;

	return;
}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main() {
	int num=0,y=0, n;
	while(cin>>n){
		num = 0;
		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 <iostream>

using namespace std;

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

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for(int a = 3;a<1000000;a++)
	{
		prime[a] = 1;
	}
	
	for(int a = 3;a<1000;a++)
	{
		if(checked[a] == 0)
		{
			checked[a] = 1;
			for(int b = 2;b<a;b++)
			{
				if(a%b==0)
				{
					prime[a] = 0;
					break;
				}
			}
			if(prime[a] == 1)
			{
				for(int c = 2*a ;c<1000000;c+=a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for(int a = 3;a<1000000;a++)
	{
		primesum[a] = primesum[a-1]+prime[a];
	}
	
	while(cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}

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

vector<int> eratosthenes(int n) {
  vector<int> res, p(n + 1, 1);
  p[0] = p[1] = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (p[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        p[j] = 0;
      }
    }
  }
  for (int i = 0; i <= n; ++i) {
    if (p[i]) res.push_back(i);
  }
  return res;
}

int main() {
  int n;
  while (cin >> n) cout << eratosthenes(n).size() << endl;
}

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

int main(){
int n,a;
int pri[99999];
pri[0]=2;
int ans=1;
while(cin>>n){
ans=1;
for(int i=3;i<n+1;i++){
pri[ans]=i;
for(int j=0;j<ans&&pri[j]*pri[j]<i+1;j++){
a=i%pri[j];
if(a==0){
ans--;
break;}
}
ans++;
}
cout<<ans<<endl;}}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;
	while(cin >> n){
		count = 1;
		for(int i = 1; i <= n; i += 2){
			if(i < 2);
			else{
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
						break;
					}
				}
				if(flag != true){
					count++;
				}
				flag = false;
			}
		}
		cout << count << endl;

	}

	return 0;
}

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

using namespace std;

int main() {
  const int N_MAX = 999999;
  const double MAX = sqrt(N_MAX);

  vector<int> preprime_list, prime_list;

  for (int i = 2; i <= N_MAX; i++) {
    preprime_list.push_back(i);
  }

  while (preprime_list[0] < MAX) {
    for (int i = 1; i < preprime_list.size(); i++) {
      if (preprime_list[i]%preprime_list[0] == 0)
        preprime_list.erase(preprime_list.begin()+i);
    }
    prime_list.push_back(preprime_list[0]);
    preprime_list.erase(preprime_list.begin()+0);
  }
  return 0;
  prime_list.insert(prime_list.end(), preprime_list.begin(), preprime_list.end());

  int data,count;
  while (cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] <= data; i++, count = i);
    cout << count << endl;
  }
}

C++: #include<iostream>
#include<math.h>
main(){
	int i,j,n,p[1000000];
	std::cin>>n;
	for(i=2;i<=n;i++)
		p[i]=1;
	for(i=2;i<n;i++)
		if(p[i])
			for(j=2;i*j<=n;j++)
				p[i*j]=0;
	j=0;
	for(i=2;i<n;i++)
		j+=p[i];
	std::cout<<j<<std::endl;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN = 1000000;
bool isPrime[MAXN];
int main(){
  fill(isPrime,isPrime+MAXN,true);
  isPrime[0] = isPrime[1] = false;
  isPrime[2] = true;
  for(int i = 0;i < MAXN;i++){
    if(isPrime[i]){
      for(int j = i*2;j < MAXN;j+=i){
        isPrime[j] = false;
      }
    }
  }
  vector<int> primes;
  for(int i = 0;i < MAXN;i++){
    if(isPrime[i])primes.push_back(i);
  }
  int n;

  while(cin >> n){
    auto a = upper_bound(primes.begin(),primes.end(),n);
    cout << a - primes.begin() << endl;
  }
}

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

int num;
bool isPrime(int n)
{
   for (int i=2;i<=static_cast<int>(sqrt(static_cast<double>(n)));i++)
   {
      if (n%i==0)
         return false;
   }

   return true;
}
int main()
{
    while(cin>>num)
    {
      int count=1;
   for (int loop=3;loop<=num; loop+=2 )
   {
      if (isPrime(loop))
      {
         count++;
      }
   }
   cout<<count<<endl;
    }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int cnt=0,res=0;
    for(int i=3; i<=n; i+=2){
      for(int j=1; j<=i/2; j++){
        if(i%j == 0) cnt++;
        if(cnt>1) break;
      }
      if(cnt==1) res++;
      cnt = 0;
    }
    cout << res+1 << endl;
  }
  return 0;
}