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<cstdio>
#include<cmath>

using namespace std;
#define MAX_N 999999
int n;//n以下の素数がいくつあるか出力する
int ans;//素数の数
int prime[MAX_N];//prime[i]が1ならば素数i+1は素数
int main(){
  while(scanf("%d",&n) != EOF){
    ans = 0;
    for(int i= 0;i < n;i++){
      prime[i]= 1;
    }
    prime[0] = 0;//1は素数でないので
    for(int i = 1;i <sqrt(n);i++){
      if(prime[i] == 1)
	for(int j =(i+1);(i+1)*j <=n;j++){
	  prime[(i+1)*j-1] = 0;
	}
  }
    for(int i = 0;i < n;i++){
      if(prime[i] == 1)
	ans++;
    }
      printf("%d\n",ans);
  }
  return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int cnt=0;
		vector<bool> v(n+1,true);
		for(int i=2; i<=sqrt(n); i++){
			if(v[i]){
				for(int j=2; i*j<=n;j++){
						v[i*j]=false;
				}
			}
		}
		for(int i=2;i<=n;i++){
			if(v[i]==true)
				cnt++;
		}
		cout << cnt << endl;
	}
}

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


int solve(int b){
    int m = 0;
    int x[1000000];
    if(b == 1){
        return 0;
    }else if(b==2){
        return 1;
    }
    x[m++] = 2;
    for(int i=3;i<=b;i+=2){
        bool a = true;
        for(int j=0;j<m;j++){
            if(i%x[j]==0){
                a = false;
                break;
            }
        }
        if(a){
            x[m++] = i;
        }
    }
    return m;
}

int main(){
    int n;
    while((cin>>n)){
        cout << solve(n) << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#define long long long
const int N = 100005;
bool np[N];
void eratos() {
    np[0]=np[1]=true;
    for (int i=2; i*i<N; i++) if (!np[i])
        for (int j=i*i; j<N; j+=i) np[j]=true;
}
main()
{
	eratos();
	long n,d=0;
do
{
    d=0;
	cin>>n;
	for(long i=0;i<=n;i++)
	if(np[i]==false)
	d++;
	cout<<d<<endl;
}while(1);
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;
      
      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]==true){
        for(int j = i;i<MAX;j*j)
        v[i]=false;
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int s[80000],m[10000000],i,j,n=0;
int main() {
	for (i=2; i<1000000 ; i++) {
		if (m[i]==0) {
			s[n++]=i;
			for (j=i; j<10000000; j+=i) m[j]=1;
		}
	}
	while(cin >> i) {
		for (j=0;s[j]<=i && j<n;j++) ;
		cout << j << endl;
	}
return 0;
}

C++: #include<stdio.h>
#define max 1000001;

int main(void)
{
	int *d, f1, f2, n, cnt;
	d = new int [max];
	for(f1 = 0; f1 < max; f1++)
	{
		d[f1] = 1;
	}
	for(f1 = 2; f1 *f1 < max; f1++)
	{
		if(d[f1] == 1)
		{
			for(f2 = 2 * f1; f2 < max; f2 += f1)
			{
				d[f2] = 0;
			}
		}
	}
	while (scanf("%d",&n) != EOF)
	{
		cnt=  0;
		for(f1 = 2; f1 >= n; f1++)
		{
			if(d[f1] == 1)
				cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int a[1000500];
int main(){
	for(int i=2;i*i<1000500;i++){
		for(int j=i*2;j<1000500;j+=i){
			a[j]=1;
		}
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=2;i<=b;i++){
			if(a[i]==0) c++;
		}
		cout<<c<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number[40] = {0};
    int answer[40] = {0};
    int i = 0,j = 0,k = 0;
    while(cin >> number[i])
    {
        for(k = number[i];k>1;k--)
            for (int l = 2; l<k; l++)
            {
                if( (k % l ) == 0)
                    break;
                if((k % l ) != 0 && (l == k -1) )
                    answer[i]++;
            }
        i++;
    }
    REP(j,i)
    cout << answer[j]+1 << endl;
    return 0;
    
}

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

int main() {
	int n, ans; bool check;
	while (cin >> n) {
		if (n == 2) { cout << "1" << endl; continue; }
		if (n == 3) { cout << "2" << endl; continue; }
		ans = 2;
		for (int i = 4; i <= n; i++) {
			if (i % 2 == 0 || i % 3 == 0) continue;
			if (i % 6 != 1 && i % 6 != 5) continue;
			check = true;
			for (int j = 5; pow(j, 2) <= i; j += 6) {
				if (i % j == 0 || i % (j + 2) == 0) check = false;
				if (check == false) break;
			}
			if (check == true) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,j,o=0;
	bool n[100000];
	for(int i=2;i<=99999;i++){
		n[i]=true;
	}
	n[0]=n[1]=false;
		for( j=2;j<=99999;j++){
			if(n[j]){
				for(int k=j*2;k<=9999;k+=j){
				n[k]=false;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
	o=0;
		}
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		bool *flag = new bool[n+1]();
		for(int i=2;i<=n;++i)
		{
			if (flag[i])
			{
				continue;
			}
			for(int j=i*2;j<=n;j+=i)
			{
				flag[j] = true;
			}
		}
		flag[0]=true;
		flag[1]=true;
		for(int i=0;i<=n;++i)
		{
			if(!flag[i])
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
}