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

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

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

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

	return 0;
}

C++: #include <bitset> // compact STL for Sieve, better than vector<bool>!
#include <vector>
#include <cstdio>
#include <iostream>
#define ll long long
#define vi vector<int>

using namespace std;

ll _sieve_size; // ll is defined as: typedef long long ll;
bitset<10000010> bs; // 10^7 should be enough for most cases
vi primes; // compact list of primes in form of vector<int>
void sieve(ll upperbound) { // create list of primes in [0..upperbound]
_sieve_size = upperbound + 1; // add 1 to include upperbound
bs.set(); // set all bits to 1
bs[0] = bs[1] = 0; // except index 0 and 1
for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
// cross out multiples of i starting from i * i!
for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i); // add this prime to the list of primes
} } // call this method in main method
bool isPrime(ll N) { // a good enough deterministic prime tester
if (N <= _sieve_size) return bs[N]; // O(1) for small primes
for (int i = 0; i < (int)primes.size(); i++)
if (N % primes[i] == 0) return false;
return true; // it takes longer time if N is a large prime!
} // note: only work for N <= (last prime in vi "primes")^2
// inside int main()
int main()
{
    int TestCase,x;
    int Counter;
sieve(1000000); // can go up to 10^7 (need few seconds)

    while(cin >> TestCase)
    {
        x=0;
        while(TestCase >= primes[x])
        {
            x++;
        }
        cout << x << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

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

int main() {
   vector<int> v(1000000,0),rui(1000000,0);
   rep(i,1,999999)if(isPrime(i))v[i]=1;
   rui[0]=v[0];
   rep(i,1,999999)rui[i]=rui[i-1]+v[i];
   
   int n;
   while(cin>>n){
       cout<<rui[n]<<endl;
   }
   
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int ans=0,math[1000001]={0};
    math[1]=1;
    for(int i=2;i<n+1;i++){
      int bell=i;
      if(math[i]==0){
	ans++;
	math[i]=1;
      }
      while(bell<=n){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      } 
    }
    cout << ans << endl;
  }
}

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;
    if(pri[j]==1){c++;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 <cmath>
#include <iostream>

using namespace std;

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

	return true;
}

int main()
{
	int N;

	static int C;

	cin >> N;

	for (int i = 2; i <= N; i++)
	{
		if (isprime(i) == true)
		{
			C += 1;
		}
	}

	cout << C << endl;

	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
bool p[M];
long long int cnt[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  cnt[0] = cnt[1] = 0;
  loop(i,2,M){
    cnt[i] = cnt[i-1] + p[i];
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
  rep(i,10)cout<<cnt[i]<<endl;
}
int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<cnt[n]<<endl;
}

C++: #include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

vector<int> vec;

void makesosuu(void){
	FOR(i, 2, 999999){
		if(i == 2){
			vec.pb(i);
		}else if(i % 2 != 0){
			bool flag = true;
			int j = 3;
			while(j * j <= i){
				if(i % j == 0){
					flag = false;
					break;
				}
				j += 2;
			}
			if(flag) vec.pb(i);
		}
	}
	return;
}

int sosuu(int n){
	int i = 0;
	while(vec[i] < n && i < vec.size()) ++i;

	return i;
}

int main(){
    int n;
    makesosuu();
    while(cin >> n){
        cout << sosuu(n) << endl;   
    }	
}

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

int prime[MAX_N];
bool is_prime[MAX_N];

int sieve(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;
		}
	}
	return p;
}

int main()
{
	int s;
	while( cin >> s )
	{
		cout << sieve(s) << endl;
	}
	
		
	return 0;	
}

C++: //Prime Number
#include<iostream>
#include<cstdio>

using namespace std;

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