Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

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

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

int main(){
	int n;
	
	while(scanf("%d",&n)==1){
	int count=0;
	double sqrtn = n;
		for(int i=3;i<=n;i+=2){
			bool p=true;
			for(int j=3;j<sqrt(sqrtn);j++){
				if(i % j == 0){
					p=false;
					break;
				}
			}
			if(p) count++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 1000100
#define LIM 1010

bool composite[MAX + 100];
int prime[MAX + 100];

void sieve()
{
    for(int i = 2; i <= LIM; i++){
        for(int j = i * i; j <= MAX; j += i)
            composite[j] = true;
    }
    int counter = 0;
    for(int i = 2; i <= MAX; i++){
        if(!composite[i]) counter += 1;
        prime[i] = counter;
    }
}

int main()
{
    sieve();
    int n;
    while(cin >> n){
        cout << prime[n] << "\n";
    }
}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<cstdio>
#include<cmath>

int main(){
    int n, cnt=0;
    scanf("%d", &n);
    for(int i = 3; i<=n; i+=2){
        int k= 0;
        for(int j=3; j<sqrt(i); j+=2){
            if(i%j==0){
                k=1;
                break;
            }
        }
        if(k==0) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}

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

bool isprime(int x){
	if(x==2) return true;
	if(x<2 && !(x%2)) return false;
	x = int(ceil(sqrt(x)));
	for(int i=3;i<=x;i+=2){
		if(!(x%i)) return false;
	}
	return true;
}

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

C++: #include<iostream>
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<String>
#include<time.h>
#include<math.h>

using namespace std;
int c = 0;
int i = 1;
unsigned long long a = 0;
unsigned long long b = 0;
unsigned long long sosuu[100000] = { 0 };
char fire = 0;
int pattara = 0;

int sub(int c) {

	
	
	
	for (int i = 2; i<=c; i++){
		
		for (int q = 1; q <= sqrt(i); q++) {
			sosuu[pattara] = i;
			if (sosuu[pattara] % 2 == 0 && sosuu[pattara]!= 2) {
				break;
			}
			if (sosuu[pattara] % q == 0) {
				b += 1;
			}

		}

		if (b == 1) {
			
			pattara++;
			
		}
		b = 0;
		
	}

	
	return 0;
}


int main(){
	while (scanf("%d", &c) != EOF){

		sub(c);
		cout << pattara << endl;
		pattara = 0;
		
	}

	return 0;
}

C++: #include<iostream>
#define Max 1000000   

bool prime[Max];  
void IsPrime(){  
     prime[0]=prime[1]=0;prime[2]=1;  
     for(int i=3;i<Max;i++)  
        prime[i]=i%2==0?0:1;  
     int t=(int)sqrt(Max*1.0);  
     for(int i=3;i<=t;i++)  
       if(prime[i])  
         for(int j=i*i;j<Max;j+=2*i)//?化    
            prime[j]=0;  
}

int main(){
	int n;
	IsPrime();
	int time=0;
	while((time<=30)&&(std::cin>>n)){
		int count=0;
		for(int i=2;i<=n;++i){
			if(prime[i]) 
				++count;
		}
		std::cout<<count<<std::endl;
		time++;
	}
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	 vector<int> a(100);
	a[0]=2;
	int z=1;
	for(int i=2;i<100000;){
		for(int j=0;j<z;j++){
			if(i%a[j]==0)goto stop;
		}
		a[z]=i;
		z++;
		stop:;
		if(i==2) i++;
		else i+=2;
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<z;i++){
			if(a[i]>b)break;
			else c++;
		}
		cout<<c;
	}
}

C++: #include <iostream>

using namespace std;

int main(){
  int n,visited,cnt=0;
  
  while(cnt<30){
    int count =0;
    cnt++;
    cin >> n;
    if(n==0)count =0;
    for(int j=2;j<=n;j++){
      visited=0;
      for(int i = 2;i<=n;i++){
	
	if(j%i==0&&j!=i)visited=1;
	else if(j%i==0&&j==i&&visited==0)count++;
	
      }
    }
    cout << count << endl;
  }
  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;
			}
		}
	}
	while (true) {
		int n;
		cin >> n;
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

C++: #include <iostream>  
#include <stdio.h>  
#include <math.h>  
#include <string.h>  
  
using namespace std;  
  
const int N = 1e6;  
const int SQRTN = ceil(sqrt((double) N));  
bool isPrime[N];  
int prefixsum[N];  
  
// Eratosthenes筛选法  
void esieve(void)  
{  
    memset(isPrime, true, sizeof(isPrime));  
  
    isPrime[0] = isPrime[1] = false;  
    for(int i=2; i<=SQRTN; i++) {  
        if(isPrime[i]) {  
            for(int j=i*i; j<=N; j+=i)  //筛选  
                isPrime[j] = false;  
        }  
    }  
}  
  
void maketable()  
{  
    prefixsum[0] = 0;  
    for(int i = 1; i <= N; i++)  
        prefixsum[i] = isPrime[i] ? prefixsum[i - 1] + 1 : prefixsum[i - 1];  
}  
  
int main()  
{  
    esieve();  
  
    maketable();  
  
    int n;  
    while(~scanf("%d", &n))  
        printf("%d\n", prefixsum[n]);  
  
    return 0;  
}

C++: #include <stdio.h>
 
#define MN 
 
int main(void)
{
    int n;
    int i, j;
	long LN = 1000001;
    int pn[1000001];
     
    for (i = 0; i < LN; i++){
        pn[i] = 1;
    }
     
    pn[0] = pn[1] = 0;
     
    for (i = 2; i * i < LN; i++){
        if (pn[i] == 1){
            for (j = i * i; j < LN; j += i){
                pn[j] = 0;
            }
        }
    }
     
    for (i = 1; i < LN - 1; i++){
        pn[i + 1] += pn[i];
    }
     
    while (cin >> n){
    	cout << pn[n] << endl;
    }
     
    return (0);
}