Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

using namespace std;


int main(int argc, const char * argv[]) {
    // insert code here...
    
    int maxNumber;
    int countPrime=0;
    bool judgePrime = true;
    
    while(cin >> maxNumber){
        for(int i=2; i<=maxNumber;i++){
            for(int j=2; j<i;j++){
                if(i%j==0){
                    judgePrime = false;
                }
            }
            if(judgePrime){countPrime++;}
            judgePrime = true;
        }
        cout << countPrime << endl;
    }
    

    return 0;
}

C++: // AOJ 009

#include <iostream>
#define MAX_NUMBER 1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples (int prime) {
	for (int i = prime*2; i < MAX_NUMBER;i+=prime) {
		isPrime[i] = false;
	}
	return;
}	

int CountPrimes(int n) {
	int count = 0;
	for (int i = 1;i <= n;i++) {
		if (isPrime[i]) count++;
	}
	return count;
}

int main() {
	for (int i = 0;i < MAX_NUMBER;i++) {
		isPrime[i] = true;	
	}
	isPrime[1] = false;
	
	for (int i = 1;i < MAX_NUMBER;i++) {
		if (isPrime[i]) {
			SetFalseToMultiples(i);
		}
	}
	int n;
	while (cin >> n) {
		cout << CountPrimes(n) << endl;
	}
	return 0;
}

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;
}