Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

int main(){
    int n;
    while(cin>>n){
        if(n == 1) {
            cout<<0<<endl;
        }
        else if(n == 2){
            cout<<1<<endl;
        }
        else{
            int num[1000000] = {};
            for(int tmp = 2;tmp != n;tmp++){
                if(num[tmp] == 0)
                for(int i = tmp * 2;i <= n;i += i){
                    num[i] = 1;
                }
            }
            int count = 0;
            for(int i = 2;i != n;i++){
                if(num[i] == 0){
                    count++;
                }
            }
            cout<<count<<endl;
        }
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

int main(){
  int n,ans[1000000]={0};
  bool num[1000000]={true};
  num[1]=true;
  for(int i=2;i<1000000;i++){
    if(num[i]==false){
      for(int j=i+i;j<1000000;j=j+i){
	num[j]=true;
      }
    }
  }

  for(int i=1;i<1000000;i++){
    ans[i]=ans[i-1]+!num[i];
    //cout<<num[i]<<endl;
  }
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  
  return 0;
}

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

bool isChecked[1000010];
vector <int> prime;

int main() {
	for (int i = 0;i < 1000000; i++) isChecked[i] = false;
	isChecked[0] = true;
	isChecked[1] = true;
	for (int i = 2; i < 1000000;i++) {
		if(isChecked[i]) continue;
		prime.push_back(i);
		for (int j = 1; j * i < 1000000;j++) {
			isChecked[j*i] = true;
		}
	}
	int n;
	while(cin >> n) {
		int i;
		for(i = 0;;i++) {
			if (prime[i] > n) break;
		}
		cout << i << endl;
	}
	return 0;
}

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

int main()
{
	vector<int> pcount;
	int prime[10000];
	int j, k, x, num,count=0;
	while (cin >> num){
		prime[0] += 2;
		x = 1;
		k = 1;
		while (prime[k-1] <= num)
		{
			x += 2;
			j = 0;
			while (j < k && x % prime[j] != 0)j++;
			if (j == k)
			{
				prime[k++];
				count++;
			}
		}
		pcount.push_back(count);
		count = 0;
	}
	for (int i = 0; i < pcount.size(); i++)
	{
		cout << pcount[i] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
int main(){
	int a[999999]={0},i,j;
	a[1]=1;
	for(i=2;i<=999999;i++){
		if(a[i]==0)for(int j=i*2;j<=999999;j+=i)a[j]=1;}
	int n;
	while(~scanf("%d",&n)){
		int sum=0;
		for(i=1;i<=n;i++){
			if(a[i]==0)sum++;}
		printf("%d\n",sum);}
	return 0;}

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

const int N = 1000010;

bool prime[N];
int number[N];
void init() {
  for (int i=0;i<N;i++) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i=0;i<=sqrt(N);i++) {
    if (prime[i]) {
      for (int j=i*2;j<N;j+=i) prime[j] = false;
    }
  }
  number[0] = 0;
  for (int i=0;i<N-1;i++) {
    number[i + 1] = number[i] + prime[i + 1];
  }
}

int main() {
  int n;
  init();
  while (cin >> n) {
    cout << number[n] << endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	scanf("%d", &n);
	
	bool *d = new bool [n+1];
	int count = 0;

	for(int i = 0; i <= n; i++)
		d[i] = true;

	for(int i = 2; i <= n; i++){
		if(d[i]){
			count++;
			for(int j = i*2; j <= n; j+=i)
				d[j] = false;
		}
	}
	printf("%d\n", count);



	return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	int n;
	while (cin>>n) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    int a[1000000]={0};
    int cont=0;
    a[1]=1;
    for(int i=2;i<=sqrt(n);i++){
      if(a[i]==0){
      for(int j=2;j<=n;j++){
	a[i*j]=1;
      }
    }
    }
    for(int i=1;i<=n;i++){
      if(a[i]==0)cont++;
    }
    cout<<cont<<endl;
  }
}

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

using namespace std;

int main(){
}

C++: #include<iostream>
#define N_MAX 999999

int prime[( N_MAX + 1 ) / 2 ];
int memo[ N_MAX + 1 ];

int mkprime( void );

int main( void )
{
	int n, i, result;

	prime[0] = 2;

	mkprime();

	while( std::cin >> n ){
		std::cout << memo[n] << std::endl;
	}
	
	return 0;
}

int mkprime( void ){
	int i, j, endindex = 1;

	for( i = 3; i < N_MAX + 1; i++ ){
		if( i % 2 == 1 ){
			for( j = 0; j < endindex; j++ ){
				if( i % prime[j] == 0 ){
					break;
				}
			}
		}

		if( prime[j] == 0 ){
			prime[ endindex ] = i;
			endindex++;
		}

		memo[i] = endindex;
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#define T 1000000
using namespace std;

signed main() {
	vector<bool>hantei(T, true);
	vector<int>sosuu(T);
	int s = 0;
	for (int a = 2; a < T; a++) {
		if (hantei[a]) {
			s++;
			for (int b = a * 2; b < T; b+=a)hantei[b] = false;
		}
		sosuu[a]=s;
	}
	while (cin >> s)cout << sosuu[s] << endl;
}

C++: #include <iostream>

using namespace std;

void solve(int n) {
	int prime[n];
	int j=0;
	for (int i=2; i<=n; i++) {
		prime[j] = i;
		j++;
	}
	int p;
	for (int i=0; i<n; i++) {
		p = prime[i];
		if (p == -1) continue;
		for (int k=i+1; k<n; k++) {
			if (prime[k]%p == 0)
				prime[k] = -1;
		}
	}
	int count = 0;
	for (int i=0; i<n; i++)
		if (prime[i] != -1) count++;
	cout << count << endl;
}

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

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

#define MAX 999999
bool flag[MAX+1];

void check_prime_num(int x){

  int way = sqrt(x);

  for(int i=2;i<way+1;++i) {
    if(x%i==0) break;
    else if(way==i) flag[x] = true;
  }

}

int solve(int n){

  int cnt = 0;

  for(int i=0;i<=n;++i){
    if(flag[i]) ++cnt;
  }

  return cnt;
}

int main(){

  int n;

  memset(flag, false, MAX);
  flag[2] = true; flag[3] = true;

  for(int i=4;i<=MAX;++i){ check_prime_num(i); }

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

}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, Array = int(1e5);
int main(){
  int n, i, j, sum;
  bool jud;
  while(cin >> n){
    sum = 0;
      for(i = 2;i <= n; i++){
        jud = 0;
        for(j = 2;(j * j) <= i; j++){
          if(i == j)  continue;
          if(!(i % j)){
            jud = 1;
            break;
          }
        }
        if(!jud)
          sum++;
      }
      cout << sum <<endl;
  }
}