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

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

int n;
int main()
{
	bool prime[1000005];
	memset(prime, true, 1000005);
	prime[0] = false; prime[1] = false;
	for (int i = 2; i*i < 1000005; i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; i*j < 1000005; j++)
			{
				prime[i*j] = false;
			}
		}
	}
	while (cin >> n)
	{
		int cnt = 0;
		REP(i, n+1)
		{
			if (prime[i] == true)
			{
				cnt++;
				//cout << i << endl;
			}
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main()
{
    int n;
    
    while(cin>>n){
        bool p[n+1];
        int cnt = 0;
        for(int i=0; i<=n; i++){
            if(i==0){
                p[0] = false;
            }
            else if(i==1){
                p[i] = false;
            }
            else if(i==2){
                p[i] = 2;
            }
            else if(i==3){
                p[i] = 3;
            }
            else if(i==5){
                p[i] = 5;
            }
            else if(i==7){
                p[i] = 7;
            }
            else if((i%2!=0)&&(i%3!=0)&&(i%5!=0)&&(i%7!=0)){
                p[i] = true;
            }
            else{
                p[i] = false;
            }
        }
        
        for(int j=0; j<=n; j++){
            if(p[j]==true){
                cnt++;
            }
        }
        
        cout << cnt << endl;
            
    }
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+10;
const int maxn=100000+5;
int prime[maxn];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt++]=i;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 1000000
bool prime[MAX];
int main(void){ 
  
  prime[0] = prime[1] = false;
  //memeset(prime,sizeof(prime),true);
  fill(prime,prime+MAX,true);
  long long int ans[MAX];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  int now=0;
  
  for(long long int i = 2 ; MAX >= i ; i ++){
    ans[i] = now ;
    //cout<<now<<" "<<ans[i]<<endl;
    if(prime[i]){
      //cout<<i<<endl;
      now ++;
      for(long long int j = i + i ; MAX > j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  long long int n;
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  
}

C++: #include<cstdio>
#define MAX 1000010

bool is_prime[MAX];

int sieve(int n) {
	for (int i = 0; i <= n; ++i) is_prime[i] = true;	
	is_prime[0] = is_prime[1] = false;
	int count = 0;
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) {
			++count;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return count;
}

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

C++: #include <stdio.h>
int isprime(int n){
	int i,j;
	int isprime[10000];
	for(i=0;i<=10000;i++){
 		isprime[i]=1;
	}
	isprime[0]=isprime[1]=0;
	for(i=2;i<=10000;i++){
 		if(isprime[i]==1){
 			for(j=2*i;j<=1000;j+=i){
				isprime[j]=0;
			}
		}
	}
}

int main(){
	int a,b,i,n,p1,q1;
	scanf("%d", &n);
	while (n != 0){
		for(i=2;i<=n;i++){
			a = isprime(i-2);
			b = isprime(i);
			if(a==1 && b==1){
				p1 = i-2;
				q1 = i;
			}
		}
		printf("%d %d\n",p1,q1);
		scanf("%d", &n);
	}
	return 0;
 }

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

int sos(int);

int pri[10000000];

int main(){
  int x;
  while(scanf("%d",&x)!=EOF){
    printf("%d\n",sos(x));
  }  
  return 0;
}

int sos(int a){
  int i,j,c=0,b;
  for(j=2;j<=a;j++){
    b=0;
    if(pri[j]==3)continue;
    for(i=2;i<=sqrt(j);i++){
      if(j%i==0){pri[j]=3;b=1;break;}
      
    }
    if(b==0){pri[j]=1;c++;}
  }
  return c;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/


int prime[1000000];
bool is_prime[1000000];

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


int main(){
  int n,cnt;
  sieve();
  while(cin>>n){
    cnt=0;
    for(int i=0;;i++){
      if(prime[i]>n)break;
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

const int N = 1000000;
bool flags[N];
int  counts[N];

void make_flags_and_counts ();

void make_flags_and_counts () {
    fill(flags, flags + N, true);
    flags[0] = false;
    flags[1] = false;

    fill(counts, counts + N, 0);
    for (int i = 2; i < N; ++i) {
        if (flags[i]) {
            for (int j = 2; i*j < N; ++j) {
                flags[i*j] = false;
            }
        }
        counts[i] = flags[i] ? counts[i-1] + 1 : counts[i-1];
    }
}

int main() {
    make_flags_and_counts();

    int n;
    while (cin >> n) {
        cout << counts[n] << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0,k;
	while(k<29){
		cin >> N;
		count = 0;
		if(N<0)	break;
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
		k++;
	}
	return 0;
}

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

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;

while(~scanf("%d",&n)){
int* table =  new int[1000000];
memset(table,sizeof(table),1);
table[0]=0;

for(int i=1;i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j*=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+1000000,1));
}
}