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++: #include <bits/stdc++.h>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    vector<int> prime;
    prime.push_back(2);
    for (long long int i = 3; i < 999999; i++)
    {
        double temp = sqrt(i);
        for (int j = 0;; j++)
        {
            if (temp < prime[j])
            {
                prime.push_back(i);
                break;
            }
            if (i % prime[j] == 0)
            {
                break; //this is not prime
            }
        }
    }
    int n;
    int i;
    while (cin >> n)
    {
        for (i = 0; i<prime.size()&&prime[i] <= n; i++);
        cout << i << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
int main(){
 int n,cnt=0;
 scanf("%d",&n);
 int a[n+1];
 memset(a,-1,sizeof(int)*(n+1));
 for(int i=2;i<=n;i++){
 if(a[i]==-1){ cnt++;
 for(int j=i;j<=n;j=j+i) a[j]=0;}
}
printf("%d",cnt);
return 0;
}

C++: #include<stdio.h>
int flg[1000000];
int main(void)
{
    int n,i,j,x;
	
    while(scanf("%d",&n)!=EOF){
		for(i=2;i<=n;i++)	{
			flg[i]=1;
		}
		for(i=2;i*i<=n;i++){
			if(flg[i]==1){
				for(j=2;j*i<=n;j++){
					flg[i*j]=0;
				}
			}
		}
		x=0;
		for(i=2;i<=n;i++)	{
			if(flg[i]==1){
				x++;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

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

bool prime[MAX]={};

void run(){
  for(int i=2;i<MAX;i++){
    prime[i]=true;
  } 

  for(int i=2;i<MAX;i++){
    if(!prime[i])continue;
    for(int j=2;j*i<MAX;j++){//i*1 is prime number
      prime[i*j]=false;
    }
  }
  return;
}

int main(){

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

}

C++: #include <iostream>                                                                                                     
#include <vector>                                                                                                       
                                                                                                                        
using namespace std;                                                                                                    
                                                                                                                        
int main() {                                                                                                            
  int n;                                                                                                                
  int count;                                                                                                            
  while (cin >> n) {                                                                                                    
    if (n == 1) { cout << 0 << endl; return 0; }                                                                        
    if (n == 2) { cout << 1 << endl; return 0; }                                                                        
                                                                                                                        
    vector<int> prime_numbers; // 素数リスト                                                                            
    prime_numbers.push_back(2);                                                                                         
    count = 1;                                                                                                          
    for (int i = 3; i <= n; i++) {                                                                                      
      bool prime = true;                                                                                                
      for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) {                      
        if (i % *itr == 0) {                                                                                            
          prime = false;                                                                                                
          break;                                                                                                        
        }                                                                                                               
      }                                                                                                                 
      if (prime) {                                                                                                      
        prime_numbers.push_back(i);                                                                                     
        count += 1;                                                                                                     
      }                                                                                                                 
    }                                                                                                                   
    cout << count << endl;                                                                                              
  }                                                                                                                     
  return 0;                                                                                                             
}

C++: $inputArray = array();
while (!feof(STDIN)) {
  $input = trim(fgets(STDIN));
  if (empty($input)) {
    break;
  }
  array_push($inputArray, $input);
}

foreach ($inputArray as $input) {
  $count = 0;
  for ($i = 2; $i <= $input; $i++) {
    if (isSosu($i)) {
      $count++;
    }
  }
  echo $count . "\n";
}

function isSosu($num) {
  $count = 0;
  for ($i = 2; $i < $num; $i++) {
    if ($num % $i == 0) {
      $count++;
    }
  }
  if ($count == 0) {
    return true;
  } else {
    return false;
  }
}

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

struct SieveOfEstosthenes {
    int n;
    vector<bool> is_prime;
    vector<int> prime;
    SieveOfEstosthenes(int n) : n(n), is_prime(n, true) {
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i <= n; ++i) {
            if (is_prime[i]) {
                prime.push_back(i);
                for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
            }
        }
    }
};

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/0009
*/
int main() {
    int n;
    while (cin >> n) {
        SieveOfEstosthenes era(n);
        cout << era.prime.size() << endl;
    }
}