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 <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  const double MAX = sqrt(99999);

  vector<int> preprime_list, prime_list;
  bool flag;

  for (int i = 2; i <= 99999; 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);
  }
  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>
using namespace std;

int main(){
	bool *map;
	int n, cnt=0;

	cin >> n;
	map = new bool[n+1];
	for( int i=2; i<=n; i++ ){
		map[i] = true;
	}

	for( int i=2; i<=n/2; i++ ){
		for( int j=2*i; j<=n; j+=i ){
			if( map[j] ){
				map[j] = false;
			}
		}
	}

	for( int i=2; i<=n; i++ ){
		if( map[i] ){
			cnt++;
		}
	}
	cout << cnt << endl;

	delete[] map;
	map = 0;
}

C++: #include <iostream>
using namespace std;
int prime[10005]= {0};
int nprime=0;
void get_prime()
{
    for(int i=2; i<10005; i++)
    {
        if(!prime[i])
        {
            for(int j=i*i; j<10005; j+=i)

            {
                prime[j]=1;
            }
        }
    }
}
void print()
{
    for(int i=1; i<10005; i++)
    {
        if(prime[i]==0)
        {
            cout <<i << " ";

        }

    }
}
int main ()
{
    int n ;
    get_prime();
    while(cin >> n )
    {
        int sum =0;
        for(int i=2; i<=n; i++)
        {
            if(prime[i]==0)
            {
                sum ++ ;
            }
        }
         cout <<sum << endl ;

    }



//        print();
}

C++: #include<iostream>
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<String>
#include<time.h>
#include<math.h>

using namespace std;
int c = 0;
int i = 1;
unsigned long long a = 0;
unsigned long long b = 0;
unsigned long long sosuu[100000] = { 0 };
char fire = 0;
int pattara = 0;

int sub(int c) {

	
	
	/*while(i>-1)*/
	for (int i = 2; i<=c; i++){
		/*for (int z = 0; z < a;z++){*/
		for (int q = 1; q <= sqrt(i); q++) {
			sosuu[pattara] = i;
			if (sosuu[pattara] % 2 == 0 && sosuu[pattara]!= 2) {
				break;
			}
			if (sosuu[pattara] % q == 0) {
				b += 1;
			}

		}

		if (b == 1) {
			/*fire = _getch();*/
			pattara++;
			
		}
		b = 0;
		/*i++;*/
	}

	
	return 0;
}


int main(){
	while (scanf("%d", &c) != EOF){

		sub(c);
		cout << pattara << endl;
		pattara = 0;
		
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

bool isprime(int n){
  if(n==2||n==3) return true;
  for(int i=2; i*i<=n; i++) if(n%i==0) return false;
  
  return true;
}

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; RE;}
    for(int i=2; i<=n; i++) prime[i]=true;
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)&&prime[i]) {
        ans++;
        for(int j=2*i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}

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

int prime[1000010];
bool is_prime[1000010];

void seive(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;
		}
	}
}
	
int main() {
	int n;
	
	seive(999999);
	
	while(cin>>n){
		int sum=0;
		
		for(int i=0;i<=n;i++)
		if(is_prime[i])
		sum++;
		
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
/*
int main(){
	
	int i,j;
	bool n[30]={false};
	for(j=0;j<28;j++){
	cin>>n[j];
	n[j]=true;
	}
	for(i=0;i<30;i++){
		if(n[i]==false){
		cout<<i<<endl;
		}
	}

return 0;
}
*/
int main(){
	int a[30],b[28];
	for(int i=1;i<=30;i++){
		a[i-1]=i;
	}
	for(int i=0;i<28;i++){
		cin>>b[i];
	}
	sort(b,b+28);
	int c[2]={0},j=-1,k=-1;
	for(int i=0;i<28;i++){
		j++;
		if(a[i]!=b[j]){
			k++;
			c[k]=a[i];
			j--;
		}
		if(j==27){
			break;
		}
	}
	if(c[0]==0){
		c[0]=29;
	}
	if(c[1]==0){
		c[1]=30;
	}
	cout<<c[0]<<endl<<c[1]<<endl;
	return 0;
}

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

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

C++: //============================================================================
// Name        : desk.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<stdio.h>
#include<iostream>
using namespace std;
int main(){

 int n=0,f=0,P=0;

 while(scanf("%d",&n)!=EOF){

 for(int i=2;i<n;i++){

	 if(n%i==0){
		f=1;
		}

 }

 if(f==0){
	 P++;
 }
 
 }
 cout<<P<<endl;
  return 0;
}

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

int main(){
	int a;
	while(cin>>a){
		int ans = 1;
		for(int i = 2; i <= a/i; i++){
			ans += i + a/i;
			if(a == i*i) ans -= i;
		}
		if(ans == 1) cout << a << endl;
	}
	return 0;
}

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

bool check(int in){
	for (int i = 3; i<=sqrt(in); i+=2){
		if (i != 3 && i % 3 == 0)	continue;
		if (i != 5 && i % 5 == 0)	continue;
		if (i != 7 && i % 7 == 0)	continue;
		if (in % i == 0)
			return false;
	}
	return true;
}

int PrimeNumber(int in, int start){
	int count = 0;
	if (in > 2)	count++;
	for (int i = start; i <=in; i+=2){
		if (check(i))	count++;
	}

	return count;
}

int main(){
	int in, count500000 = PrimeNumber(500000, 3);

	while (cin >> in, !cin.eof()){
		if (in <= 500000)
			cout << PrimeNumber(in, 3) << endl;
		else
			cout << count500000 + PrimeNumber(in, 500001) << endl;
	}
}