Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

int a[1000000]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 1000000; i++){
		for(int j = 0; j < 1000000; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		for(int j = 2; j <= n; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

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

using namespace std;

int main(void) {
	int n;
	
	vector<int> prmcnt_v;

	while(cin >> n) {
		int pcnt = 0;
		for (int i = 2; i <= n; i++) {
			if (i % 2 == 0 && i != 2) {
				continue;
			}

			for (int j = 2; j <= i; j++) {
				if (i % j == 0){
					if (i == j) {
						pcnt++;
					}
					else {
						break;
					}
				}
			}
		}
		prmcnt_v.push_back(pcnt);
	}


	for (int k = 0; k < prmcnt_v.size(); k++) {
		cout << prmcnt_v[k] << endl;
	}

	return 0;
}

C++:  #include <iostream>
using namespace std;
int main(){
	unsigned long 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<iostream>
#include<stdio.h>
using namespace std;
int prime[1000000];
bool is_prime[1000000];
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;
	while (scanf("%d",&n)) {
		printf("%d\n", sieve(n));
	}
			
	

    return 0;
}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<endl;}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;tag:m[i]=e;}}

C++: #include <stdio.h>
#include <math.h>

int main(){
	int  n,i,j,sqrtn,sum;
	while(scanf("%d",&n)!=EOF){
		sum=n-1;
		for(i=2;i<=n;i++){
			sqrtn=(int)sqrt(i)+1;
			for(j=2;j<sqrtn;j++){
				if(i%j==0){
					sum--;
					break;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 1000000
bool p[1000000];
int main(){
  int n;

  for(int i=0;i<N;i++)p[i]=true;
  p[0]=p[1]=false;
  for(int i=0;i<N;i++)
    if(p[i]==true)
      for(int j=i*2;j<N;j+=i)
	p[j]=false;

  while(cin>>n){
    int count=0;
    for(int i=0;i<=n;i++)
      if(p[i]==true)count++;
    cout<<count<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	int n;
	cin >> n;
	
	vector <bool> p(n+1, true);
	p[0] = p[1] = false;
	for ( int i = 4; i <= n; i += 2 )
	{
		p[i] = false;
	}
	for ( int i = 3; i <= n; i += 2 )
	{
		if ( p[i] )
		{
			for ( int j = i+i; j <= n; j += i )
			{
				p[j] = false;
			}
		}
	}

	int kotae = 1;
	for ( int i = 3; i <= n; i += 2 )
	{
		if ( p[i] )
			kotae++;
	}

	cout << kotae;

	return 0;
}

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

map<int,bool>memo;

bool isprime(int q){
	map<int,bool>::iterator it;
	it=memo.find(q);
	if(it!=memo.end())return (*it).second;
	bool ret=true;
	if(q==2){
	}else if(q%2==0){
		ret=false;
	}else{
		int max=sqrt(q);
		for(int i=3;i<q;i=i+2){
			if(q%i==0)ret=false;
			break;
		}
	}
	memo.insert(pair<int,bool>(q,ret));
	return ret;
}

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

C++: #include<iostream>
using namespace std;
int main(){
  int a,t[1000000],u[1000000];
  for(int i=0;i<1000000;i++){
    t[i]=1;
  }
  t[0]=t[1]=u[1]=0;
  for(int i=2;i*i<=1000000;i++){
    if(t[i]==1){
      for(int j=i+i;j<1000000;j+=i)t[j]=0;
      u[i]=u[i-1]+1;
    }else{
      u[i]=u[i-1];
    }
  }
  while(cin>>a){
    cout<<u[a]<<endl;
  }
  return 0;
}

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

int main(){
	bool is_prime[100000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<100000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<100000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<100000;j+=i){
				is_prime[j]=false;
				}
			}
		}
		
		int n_prime[100000];
		
		int cnt=0;
		for(int i=0;i<100000;i++){
			if(is_prime[i]){
				cnt++;
			}
			n_prime[i]=cnt;
		}
		
		while(true){
			int n;
			cin>>n;
			if(cin.eof())
				break;
				
			cout<<n_prime[n]<<endl;
		}
		
		return 0;
}

C++: #include <iostream>

using namespace std;

int vtoad(int);

int main(void){
	char	*val;
	int	c,N,ad;

	while(cin >> N){
		c=2;
		if(N==1||N==2)
			c=N-1;
		else{
			val = new char[N/3+2];
			for(int i=0;i<N/3+2;i++)
				val[i]=0;

			for(int i=1;i*6-1<=N;i++)
				for(int j=-1;j<=1;j+=2)
					if(i*6+j<=N&&(ad=vtoad(i*6+j)))
						if(!val[ad]){
							c++;
							for(int k=2;(i*6+j)*k<=N;k++)
								if(ad=vtoad((i*6+j)*k))
									val[ad]=1;
					}
			delete [] val;
		}
		cout << c << endl;
	}

	return 0;
}

int vtoad(int val){
	if(!((val+1)%6))
		return (val+1)/3-1;
	else if(!((val-1)%6))
		return (val-1)/3+2;
	else
		return 0;
}

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

int main()
{
  int n;
  int count=0;
  while(cin >> n){
    double nd=(double)n;
    int root=(int)sqrt(nd);
    
    for(int i=2;i<=n;i++){
      for(int j=2;j<=root;j++){
        if(i%j==0) break;
      }
      if(j==root) count++;
    }
    cout << count << endl;
  }
  
  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	int i, k, v;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	for(i=0;i<30;i++){
		scanf("%d", &v);
		int count = 0;
		for(i=0;i<=v;i++){
			int isprime = prime[i];
			if(isprime) count ++;
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
bool us[1000010]={false};
int p[1000010] = {0};
int main(){
	/*Eratosthenes*/
	p[0] = 2;
	for(int i = 0; i <= 1000010; i+=2){
		us[i] = true;
	}
	
	int cnt = 1;
	for(int i = 3; i <= 1000010; i+=2){
		int q = 0;
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[cnt] = i;
			cnt++;
			us[i] = true;
			q = i;
			for(int j = q+q; j <= 1000010; j += q){
				us[j] = true;
			}
		}
	}
	
	int n;
	while(~scanf("%d",&n)){
		int x = 0;
		while(1){
			if(p[x] > n)break;
			x++;
		}
		printf("%d\n",x);
	}
	return 0;
}

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

int main(){
	using namespace std;
	while(1){
		int n,i,j=2,count = 0,limit;
		cin >> n;
		if (cin.eof() || n == 0) break;
		int prime[n+1];
		for(i=2;i<=n;i++) prime[i] = 1;
		limit = sqrt(n);
		for(i=2;i<=limit;i++){
			if(prime[i] == 0) continue;
			else{
				for(j=2*i;j<=n;j++){
					if(j%i == 0) prime[j] = 0;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(prime[i] == 1) count += 1;
		}
		cout << count << endl;
	}
	return 0;
}