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 := i - 1; j >= 1; j-- {
				if i%j == 0 && j != 1 {
					flag = true
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool notprime[1000000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 1000000; i++) {
		notprime[i] = false;
	}
	while (cin >> n && checkcnt < 30) {
		cnt = 0;
		int i;
		for (i = 2; i < sqrt(n); i++) {
			if (!notprime[i]) {
				cnt++;
				for (int j = 2; j <= n / i; j++) {
					notprime[i * j] = true;
				}
			}
		}
		for (int k = i; k <= n; k++) {
			if (!notprime[k]) {
				cnt++;
			}
		}
		cout << cnt << endl;
		checkcnt++;
	}
	return 0;
}

C++: #include <stdio.h>

#define NUM_MAX (1000000)

int
main(void)
{
	bool a[NUM_MAX];

	for (int i = 0; i < NUM_MAX; i++) {
		a[i] = true;
	}
	for (int i = 2; i*i < NUM_MAX; i++) {
		if (a[i]) {
			for (int j= i*i; j < NUM_MAX; j += i) {
				a[j] = false;
			}
		}
	}
	
	char line[80];
	int n;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &n) == 1) {
			int s = 0;
			for (int i = 2; i <= n; i++) {
				if (a[i]) {
					s ++;
				}
			}

			printf("%d\n", s);
		}
	}

	return 0;
}

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

bool isPrime(int x){
	for(int i=2;i<x;i++){
		if(x % i == 0) return false;
	}
	return true;
}

int main(void){
	int n;
	int ans = 0;
	
	cin>>n;
	for(int i=2;i<n;i++){
		if(isPrime(i)) ans++;
	}
	printf("%d\n",ans);

	return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int data=1,i,j,s[1000000],x;

	while((scanf("%d\n",&data)) != EOF)
	{
		for(i=0;i<=data;i++){
			s[i]=1;}
		x=0;
		if(data<=1){
			printf("%d\n",0);}
		else
		{
			for(i=2;i<=data/2;i++){
			  if(s[i]!=0){
				for(j=i*2;j<data;j+=i)
				    s[j]=0;
			  }
		for(i=0;i<data;i++)
			x+=s[i];
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include<cstdio>
using namespace std;
const int N = 1000000;

int main(){

  int IsPrime[N];
  IsPrime[0] = -1;
  IsPrime[1] = -1;
  for(int i=2; i*i<=N;i++){
    if(IsPrime[i]==0){
      IsPrime[i] = 1;
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = -1;
      }
  }
  int max;
  while(~scanf("%d",&max)){
    int count=0;
    for(int i=2; i<max+1; i++)
      if(IsPrime[i]==1) count++;
    printf("%d\n",count);
  }
}

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

bool IsPrime[1000000];
int PrimeNum[1000000];

int main()
{
    for (int i = 0; i < 1000000; i++)
    {
        IsPrime[i] = true;
    }
    int count = 0;
    PrimeNum[0] = PrimeNum[1] = 0;
    for (int i = 2; i < 1000000; i++) {
        if (IsPrime[i]) {
            count++;
            PrimeNum[i] = count;
            for (int j = 2 * i; j < 1000000; j += i) {
                IsPrime[j] = false;
            }
        }
        else
        {
            PrimeNum[i] = PrimeNum[i - 1];
        }
    }
    int n;
    while (cin >> n)
    {
        cout << PrimeNum[n] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int max = 1000100;
	bool prime[1000100];
	int dp[1000000];
	prime[0] = prime[1] = false;
	int ret=0;
	memset(prime,true,sizeof(prime));
	memset(dp,0,sizeof(dp));
	int hako[30];
	memset(hako,0,sizeof(hako));
	REP(i,30) cin >> hako[i];
	for(int i=2;i<sqrt(max);i++)for(int j=i*2;j<max;j=j+i){
		prime[j] = false;
	}
	REP(i,max){
		dp[i]=dp[i-1];
		if(prime[i])dp[i]++;
	}
	REP(i,30)	cout << dp[hako[i]] << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int prime[N], cnt;
bool st[N];
void init() {
    st[0] = st[1] = true;
    for(int i = 2; i < N; i++) {
        if(!st[i])  prime[cnt++] = i;
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = true;
            if(i % prime[j] == 0)   break;
        }
    }
}
int main() {
    init();
    // for(int i = 0; i < 10; i++)
    //     printf("%d ", st[i]);
    // puts("");
    int n, sum;
    while(cin >> n) {
        sum = 0;
        for(int i = 2; i <= n; i++)
            if(!st[i])
                sum++;
        printf("%d\n", sum);
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int prime(int);

int main() {

	int n;

	while(cin >> n) {
		if(n>999999)
			continue;
		cout << prime(n) << endl;
	}

	return 0;

}

int prime(int n) {

	int i, j, k=0, count=0;
	if(n==0||n==1)
		return 0;

	for(i=2; i<=n; i++) {
		for(j=2; j<i; j++) { 
			if(i%j==0)
				k=1;
		}
		if(k==0)
			count++;
		k=0;
	}

	return count;

}

C++: #include <iostream>
using namespace std;
int main(){
	int n , i , j;
	while(cin >> n ){
		int counter = 0;
		for( int i=1 ; i<=n ; i++ ){
			if( i%2 == 0 ){
				continue ;
			}
			int x = i;
			if( i>=6 )
				x = x /2;
			int temple=0;
			for( int j=1 ; j<=x ; j++ ){
				if( i%j == 0 )
					temple++;
			}
			if( temple == 2 )
				counter ++;
		}
		cout << counter << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
long n,i,j,*nn;
for(;;){
cin>>n;
if(cin.eof())break;
nn=new long [n+1];
nn[1]=0;nn[2]=1;
for(i=3;i<=n;i+=2)nn[i]=1;
for(i=4;i<=n;i+=2)nn[i]=0;
for(i=3;i<=n;i+=2){
for(j=i;j*j<=n;j+=2){
if(i%j==0){nn[i]=0;break;}
}
}
cout<<j<<endl;
delete [] nn;
}
return 0;
}

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

int main() {
	std::string line;
	while( std::getline( std::cin, line ) ) {
		int const num = std::atoi( line.c_str() );
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 ) {
			if ( [&i]() -> bool
			{
				for( int j=3; j<=std::sqrt(i); j+=2 )
					if ( i % j == 0 )
						return false;
				return true;
			}() )
				++result;
		}
		std::cout << result << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 10000000
bool prime[MAX-1];
int main(void){ 
  
  prime[0] = prime[1] = false;
  fill(prime,prime+MAX,true);

  int ans[1000000];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  for(int i = 2 ; MAX > i * i ; i ++){
    ans[i] = ans[i-1] + prime[i];
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  //cout<<endl;
  //for(int i = 0 ; i < 10 ; i ++)cout<<ans[i]<<endl;
  //*/
  int n;
  while(cin>>n){
    //cout<<n<<" ";
    cout<<ans[n]<<endl;
  }
  //*/
}