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>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>N;vect.resize(N);REP(i,_N){cin>>vect[i];}}
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
#define beginend(vec) (vec).begin(),(vec).end()
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}


int main() {
	ll n;
	vector<ll> ans;
	while (cin >> n)
	{
		if (n == 1) {
			ans.push_back(0);
			continue;
		}
		int prime;
		double sqrtmax = sqrt(n);
		vector<ll> primeVec, searchVec;
		FOR(i, 2, n + 1) searchVec.push_back(i);
		do
		{
			prime = searchVec[0];
			primeVec.push_back(prime);
			auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });
			searchVec.erase(itr, searchVec.end());
		} while (prime < sqrtmax);
		ans.push_back(primeVec.size() + searchVec.size());
	}
	Foreach(i, ans) out(i);
	return 0;
}

C++: #include <iostream>

int main() {
	int n;
	while (std::cin >> n) {
		int c = 0;
		for (int i = 2; i <= n; i++) {
			bool fg = true;
			for (int j = 2; j < i; j++)
				if (!(i % j))
					fg = false;
			if (fg)
				c++;
		}
		std::cout << c << std::endl;
	}
}

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

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

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 n;
  cin >> n;
  cout << sieve(n) << endl;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cmath>

using namespace std;

int pri[1000009];
int vis[1000009];

void fun()
{
    int num=0;
    for(int i=2;i<=999999;i++)
    {
        if(vis[i]==0)
        {
            pri[num++]=i;
            for(int j=i;j<=999999;j+=i)
                vis[j]=1;
        }
    }
}

int main()
{
    int n;
    fun();

    while(~scanf("%d",&n))
    {
        int num=0;
        for(int i=0;;i++)
        {
            if(pri[i]>n)break;
            else num++;
        }
        printf("%d\n",num);
    }
    return 0;
}

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

int const M=31;
int a,hantei[M];

int main(){
  hantei[0]=hantei[1]=1;
  for(int i=2;i<M;i++){
    if(hantei[i]==0){
      for(int j=2;j*i<M;j++){
	if(j*i<M){
	  hantei[j*i]=1;
	}
      }
    }
  }
  for(;cin>>a;){
    int count=0;
    for(int i=0;i<=a;i++){
      if(hantei[i]==0){
	count++;
      }
    }
    cout<<count<<endl;
  }
}

C++:  #include <iostream>
using namespace std;
int main(){
	int n , i , j , ans , num ;
	while(cin>>n){
		ans=0;
		for( i=2 ; i<=n ; i++ ){
			num=0;
			for( j=2 ; j<=n ; j++ ){
				if( i%j ==0 )
					num++;
			}
			if( num<2 )
				ans++;
		}
		cout << ans << endl;
	}
}

C++: #include <stdio.h>
 
using namespace std;
 
int calcLimit(int n){
    int limit;
    for(limit=0;limit*limit<=n;limit++);
    return limit-1;
}
 
int main(){
    int n,count,limit;
 
    while(scanf("%d",&n)!=EOF){
        count=0;
        int* array = new int[n+1];
        for(int i=1;i<=n;i++)array[i]=0;
        limit = calcLimit(n);
        for(int i=2;i<=limit;i++){
            if(array[i] == 0)
            {
                for(int j=2*i;j<=n;j+=i){
                    if(array[j]==0){
                        array[j]=1;
                        count++;
                    }
                }
            }
        }
        printf("%d\n",n-(count+1));
    }
 
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;



int erat(int num){
int i,cnt=1;
//	vector<int> Prime(num+2); // 素数リスト
	vector<char> Find(num+2); // 探索リスト
	for(int i = 2; i <= num; i++) Find[i] = '0';
	for(int i = 2; i*i < num; i++){
    	if(Find[i] > '0') continue; // すでに除いた数は飛ばす

    // j++からj+=iになったのでループ内でiの倍数のみが処理される。だいぶ高速化
    	for(int j = i * 2; j< num; j += i) {
        	if(Find[j]=='0') Find[j] = '1';
    	}
	}
// 2の倍数の素数は2だけなので奇数のみを判定
//	Prime.push_back(2);
//	for(int i = 3; i*i < num; i += 2){
//    	if(Find[i]='0') Prime.push_back(i);
//	}
	rep2(i,3,num) if(Find[i]=='0' && i % 2) { cnt++;}
	return cnt;
}

int main(void){

int num;

	while(cin >> num){
//		cnt = erst(num);
		cout << erat(num) <<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
#define thefor(i,end) for (i=0;i<end;i++)
bool isprime(int n)
{
	if(n==1)return false;
	if(n==2)return true;
	for (int i=3;i<n;i++)
	{
		if (n%i==0)return false;
	}
	if (i==n)
		return true;		
	else
		return false;
}
int main()
{
	bool prime[1000010];
	memset(prime,1,1000010);
	prime[0]=prime[1]=0;
	int i,j,n,sum;
	for (i=2;i<1000000;i++)
	{
		if (prime[i])
		{
			for (j=2;i*j<1000000;j++)
			{
				prime[i*j]=false;
			}
		}
	}
	while(cin>>n)
	{
		sum=0;
		for(i=2;i<=n;i++)
		{
			sum+=prime[i];
		}
		cout<<sum<<endl;

	}	
	return 0;
}

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

int main(){
  int n;

  while(cin >> n){
    int cnt = 0;
    
    for(int i = 1; i <= n; i++){

      if(i % 2 == 0|| i % 3 == 0 || i % 5 == 0) continue;

      int yakusuu = 0;

      for(int j = 1; j <= i; j++){
        if(i % j == 0) yakusuu++;
      }

      if(yakusuu == 2) cnt++;

    }
    
    cout << cnt + 3 - 1 << endl;
  }
  return 0;
}