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 := 2; j < i-1; j++ {
				if i%j == 0 && j != 1 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

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

int main()
{
     while(1){
     long int xx,sqrtx,q,count=1; 
     long double n;
	cin >> n;
	xx=n;
	sqrtx = sqrt(n);

	long int *ar = new long int [xx];
	long int *p = new long int [xx];
	for(long int i=2 ; i<=xx ; i++){    // 2〜xまでの整数
		ar[i]=i;
	}

	int i=2;
	do{
		if(ar[i]!=0){
			p[count]=i;
			count++;
		}
		for(int j=2*i ; j<=xx ; j+=i){
			ar[j]=0;
		}	
		i++;
	}while(i<sqrtx);

	cout << p[count-1] << endl;
        }
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=sqrt(j);i+=2){
				if(j%i==0)k++;
			}
			if(k==1)kk++;
		}
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<"1"<<endl;
		else cout<<kk+1<<endl;
	}
	return 0;
}

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

Int pn[1000002];

int main(){
int n, Count;
cin.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,n);
pn[0]=pn[1]=1;
for(int i=2;i<=n;i++) if(!pn[i]) for(int j=1;i*j<=n;j++) pn[i*j]=1;
Count=count(pn,pn+n,0);
cout<<Count<<endl;
}
return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

const int MAX_N = 1e6+5;
int prime[MAX_N];
bool is_prime[MAX_N];

int seive(int n) {
  rep(i, 0, MAX_N) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

  int p = 0;

  rep(i, 2, n+1) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
    }
  }

  return p;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  while (cin >> n) {
    cout << seive(n) << endl;
  }

  return 0;
};

C++: #include <iostream>
#include <cmath>

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; i++)
	{
		Counter += CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (IsPrime(N))
		return 1;

	return 0;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

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

int main(){
  int n,i;
i=0;
vector<int> an(1000000),as(1000000);
an[0]=2;
  for(int j=3;j<1000000;j++){
   for(int u=0;u<1000000;u++){
if(an[u]==0){
an[u]=j;
break;
}
if(j%an[u]==0){
break;
}
else{
continue;
}
}
}
   for(int u=1;u<1000000;u++){
if(u==an[i]){
as[u]=as[u-1]+1;
}
else{
as[u]=as[u-1];
}
}
for(int i=0;i<30;i++){
   cin>>n;
cout<<as[n]<<endl;
}
}

C++: #include<stdio.h>
 int prime[1000000];
 int main(){ prime[0]=-1; 
prime[1]=-1; for(int i=2;i<1000000;i++){
 if(prime[i]==0){ prime[i]=1;
 for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
 } 
} 
int now;
 while(~scanf("%d",&now)){ 
int ans=0; for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
 printf("%d\n",ans); 
}
 }

C++: #include <iostream>
#include <cmath>
using namespace std;
const int maxn = 1000000;
int dp[maxn];
bool ar[maxn];
int main()
{
	for(int i = 2;i<=maxn;i++)
	{
		if(!ar[i])
		{
			for(int j = 2;j*i<maxn;j++)
				ar[i*j] = true;
		}
		dp[i] = dp[i-1] + !ar[i];
	}
	int n;
	while(cin >> n)
		cout << dp[n] <<endl;
	return 0;
}

C++: #include <stdio.h>

bool mark[1000000];
void init() {
	for(int i=0; i < 1000000; i++) mark[i] = false;
	
	mark[0] = true;
	mark[1] = true;
	for(int i = 2;i < 1000000;i++)
	{
		if(mark[i])
			continue;
		for(int j = i * 2; j < 1000000; j += i)
		{
			mark[j] = true;
		}
		
	}

}
int main() {
	init();
	int n, count=0;
	//if(freopen("D:\\test.txt", "r", stdin) == NULL) return -1;
	while(scanf("%d", &n) != EOF) {
		for(int i = 2; i <= n;i++)
		{
			if(!mark[i])
			{
				count++;
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
    long long n;

    while (scanf("%lld", &n) != EOF){
        int cnt = 0;
        for (int i = n; i >= 2 ; i--){
            for (int j = 2; j < i; j++){
                if (i % j == 0){
                    //printf("%d\n", i);
                    cnt++;
                    break;
                }
            }
        }
        printf("%d\n", n - 1 - cnt);
    }

    return (0);
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n){
    int i;
        i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)  return false;
            i += 2;
        }
    return true;
}
 
int main(void){
    int n, i, cnt;
    while(cin >> n){
        cnt = 1;
        for(i = 3; i <= n; i = i + 2){
            if(isPrime(i))  cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

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

inline int isPrime(int x){
  if(x<=1)return 0;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return 0;
  }
  return 1;
}

int p[1001000];
int main(){
  for(int i=1;i<1000000;i++){
    p[i] = p[i-1] + isPrime(i);
  }

  int n;
  while(cin >> n){
    cout << p[n] << endl;
  }
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	int premaxin=1;


	for(i=0;i<100000;i++){
		c[i]=1;
		data[i]=0;
	}
	c[0]=c[1]=0;

	while(scanf("%d",&n)!=EOF){

		if(premaxin<n){
			for(i=0;i<=n;i++){
				if(c[i]==1){
					if(premaxin>i){
						j=premaxin;
					}else{
						j=i+1;
					}
					for(;j<=n;j++){
						if(j%i==0){
							c[j]==0;
						}
					}
				}
			}

			count=data[premaxin];
			for(i=premaxin+1;i<=n;i++){

				if(c[i]==1){
					count++;
				}
				data[i]=count;
			}
		}

		printf("%d\n",data[n]);
	}
	return 0;
}