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>

void setPrimesUnder(int n, bool *p){
    if(n > 2){
        setPrimesUnder(sqrt(n), p);
        for(int i=2; i<=sqrt(n); i++){
            if(!p[i])                       // if i is not a prime
                continue;                   // i++
            for(int j=2; j<=1000000/i; j++) // if i is a prime
                p[i*j] = false;             // the other multiples of i is not a prime
        }
    }
    else{
        p[0] = false;
        p[1] = false;
        p[2] = true;
    }
}

int main(){
    int n;
    bool p[1000000];
    for(int i=0; i<1000000; i++)
        p[i] = true;
    setPrimesUnder(1000000, p);
    
    while(std::cin >> n){
        int count = 0;
        for(int i=0; i<=n; i++){
            if(p[i])
                count++;
        }
        std::cout << count << std::endl;
    }
    return 0;
}

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

bool IsPrime(int m){
    if(m==1){
        return(0);
    }else if(m==2){
        return(1);
    }else if(m%2==0){
        return(0);
    }else{
        for(int i=3;i*i<=m;i+=2){
            if(m%i==0)return(0);
        }
        return(1);
    }
}

int main(){
    int n;
    int r[30];
    bool p[1000000];
    for(int i=1;i<=999999;i++){
        p[i]=IsPrime(i);
    }
    for(int i=0;i<30;i++){
        r[i]=0;
    }
    int j=0;
    while(cin>>n){
        for(int i=1;i<=n;i++){
            r[j]+=p[i];
        }
        cout<<r[j]<<endl;
        j++;
    }
    return(0);
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[1000000];
	int count;
	int maxin=0;
	c[0]=c[1]=0;
	for(i=2;i<1000000;i++){
		c[i]=1;
	}

	while(scanf("%d",&n)!=EOF){
		if(n>maxin){
			maxin=n;
		}
		count=n;

		
		for(i=0;i*i<=n;i++){
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0){
						c[j]==0;
						count--;
					}
				}
			}
		}

		printf("%d",count);


	}





	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n;
bool is_prime[100000];
int prime[100000];

int main(int argc, char const* argv[])
{
	fill(is_prime, is_prime+100000, true);
	is_prime[0] = false;
	is_prime[1] = false;
	int res = 0;
	for(int i = 2; i < 100000; i++){
			if(is_prime[i]){
					res++;
					for(int j = 2; j * i < 100000; j++){
							is_prime[j * i] = false;
					}
			}
			prime[i] = res;
	}
	while(cin >> n){
			cout << prime[n] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
	int n[30];
	bool po[1000001]={false};
	bool prime[1000001]={0};
	po[0]=true;
	po[1]=true;
	int cnt;
	while(cin>>n[cnt]) cnt++;

	int m=0;
	rep(i,cnt) m=max(n[i],m);

	for(int j=2;j<=m;j++){
		if(po[j]){
			prime[j]=prime[j-1];
			continue;
		}
		prime[j]=prime[j-1]+1;
		for(int k=j;k<=m;k++) po[k]=true;
	}

	rep(i,cnt) cout << prime[i] << endl;

        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++)
				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<iostream>
int r(int n){if(n<2)return 0;else if(n==2)return 1;if((n&1)==0)return 0;for(int i=3;i*i<=n;i+=2)if(n%i==0)return 0;return 1;}int main(){int n,s,i,p;for(;!(std::cin>>n).eof();){for(i=p=0;i++<=n;)p+=r(i);printf("%d\n",p);}}

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

bool dec(int value) {
  for (int j = 3; j <= value/2; j += 2) {
    if (value % j == 0) { return false; }
  }
  return true;
}

int main() {
  int n;
  while (cin >> n) {
    int count = 0;
    if (n >= 2) { count++; }
    for (int i = 3; i <= n; i += 2) {
      if (dec(i)) { count++; } 
    }
    cout << count << endl;
  }
  return 0;
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 2;
		if (cin.eof())
			return 0;
		for (int i = 5; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

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

C++: //艾氏&#31579;法
#include <iostream>
using namespace std;
#define MAX_N 999999+16

int prime[MAX_N];//保存素数
bool is_prime[MAX_N + 1];//第几个数字是不是素数
int sieve(int n){
	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;
	//其&#23454;可以&#20026;sqrt(n)
	for (int i = 2; i <= n; ++i){
		if (is_prime[i])
			prime[p++] = i;
			for (int j = i * i; j <= n; j += i)
				is_prime[j] = false;
	}
	return p;
}
int main(){
	
	int n;
	while (cin >> n){
		cout << sieve(n) << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
	int i,j,n;
	bool judge[1000000]={0};
	
	for(i=3; i<1000000; i++)if(i % 2 == 0)judge[i] = 1;
	
	for(i=3; i<500000; i+=2){
		if(judge[i]==0){
			for(j=i*2;j<1000000;j+=i){
				if(j % i == 0){
					judge[j]=1;
				}
			}
		}
	}
	
	for(;;){
		int count=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=3;i<=n;i+=2){
			if(judge[i]==0)count++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}

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

int main() {
	vector<int> nPrimes;
	vector<bool> isPrime;
	vector<int> inputs;
	int maxN, sqrtMax, n;

	maxN = 0;
	while(scanf("%d", &n) != EOF) {
		if(n > maxN)	maxN = n;
		inputs.push_back(n);
	}

	sqrtMax = sqrt(maxN-1) + 1;

	isPrime.resize(maxN, true);
	nPrimes.resize(maxN, 0);

	isPrime[0] = false;

	for(int i=2; i<=sqrtMax; ++i) {
		if(isPrime[i-1] == false)	continue;
		for(int j=2*i; j<=maxN; j+=i) {
			isPrime[j-1] = false;
		}
	}
	for(int i=1; i<maxN; ++i) {
		if(isPrime[i])	nPrimes[i] = nPrimes[i-1] + 1;
		else	nPrimes[i] = nPrimes[i-1];
	}

	for(auto it=inputs.begin(); it!=inputs.end(); ++it) {
		printf("%d\n", nPrimes[(*it)-1]);
	}
}