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

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

#define Max 1000000

int prime [10000000];

int main()
{
	int n, out;

	for (int i = 2; i * i < Max ; i++){
		if (prime[i] == 0){
			for (int j = 2 * i; j < (Max / i); j += i){
				prime[j] = 1;
			}
		}
	}

	while (cin >> n){
		out = 0;
		for (int i = 0; i <= n; i++){
			if (prime[i] == 0) out++;
		}
		cout << out - 2 << endl;
	}
	return(0);
}

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

C++: #include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];//t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j] = true;
		}
		}
		t[i]=t[i-1]+!c[i];
	}
	/*for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}*/
	for(int n;scanf("%d", &n);n++){
		printf("%d\n", t[n]);
	}
	return 0;
}

C++: #include<stdio.h>

int s[1000000] = {0};

int main(){
	int a,b,c,d,e;
	int temp;
	int cont = 0;
	
	while(scanf("%d",&a) != EOF){
		/*
		for(int i = 0; i < a; i++){
			s[i] = 1;
		}
		*/
		
		cont = 0;
		
		s[0] = 1;
		s[1] = 1;
		
		for(temp = 2; temp < a; temp++){
			if(s[temp] == 0){
				for(b=temp; b < a; b+= temp){
					if(b == temp){
						s[b] = 0;
					}
					else{
						s[b] = 1;
					}
				}
			}
		}
		
		for(c = 0; c < a; c++){
			if(s[c] == 0){
				
	//		printf("%d\n",c);
				cont++;
			}
		}
		
		printf("%d\n",cont);
	}
}

C++: #include<iostream>
using namespace std;
#define REP(i,n) for(unsigned int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define MAX 100001

bool N[MAX] = {};

int M[MAX] = {};

void SoE()
{
	REP(i, MAX)N[i] = true;

	N[1] = true;
	for (unsigned int i = 2; i*i <= MAX; i++)
	{
		for (unsigned int j = i+i; j < MAX; j += i)
		{
			N[j] = false;
		}
	}
}

void Count()
{
	M[1] = 0;
	FOR(i, 2, MAX - 1)
	{
		int add = 0;
		if (N[i] == true)
		{
			add = 1;
		}
		M[i] = M[i - 1] + add;
	}
}

int main()
{
	SoE();
	Count();
	int tmp;
	while (cin >> tmp)
	{
		cout << M[tmp] << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;

vector<int>primenumber;
int d[1050000];

int main()
{
	int n;
	
	primenumber.push_back(2);
	d[2] = 1;

	int maxn = 0;

	while (cin >> n) {
		if (maxn<n) {
			for (int i = max(maxn+1,3); i <= n; i++) {
				int ope = 1;
				for (int j = 0; j < primenumber.size(); j++) {
					if (primenumber[j] * primenumber[j] > i)break;
					if (i%primenumber[j] == 0) {
						ope = 0;
						break;
					}
				}
				if (ope == 1)primenumber.push_back(i);
				d[i] = primenumber.size();
			}
			maxn = n;
		}
		cout << d[n] << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=99,a,b,c;
    char x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string.h>

using namespace std;



void markMultiples(bool arr[], int a, int n)
{
    int i = 2, num;
    while ( (num = i*a) <= n )
    {
        arr[ num-1 ] = 1; 
        ++i;
    }
}
 

void Sieve(int n)
{
	int count=0;
    
    if (n >= 2)
    {
        
        bool arr[n];
        memset(arr, 0, sizeof(arr));
 
        
        for (int i=1; i<n; ++i)
        {
            if ( arr[i] == 0 )
            {
                
                count++;
                markMultiples(arr, i+1, n);
            }
        }
    }
    cout<<count<<endl;
}
 

int main()
{
	for (int i=0; i<=30; i++)
	{
	
    int n ;
    cin >> n;
    
    
    Sieve(n);}
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>

using namespace std;

bool prime(int p){
	if ((p==0)||(p==1)){return false;}
	else if(p==2){return true;}
	else{
		for(int i=2; i*i<=p; i++){
			if(p%i == 0){return false;}
		}
	}
	return true;
}

int main()
{
	int n;
	map<int,bool> p;

	while(cin >> n){
		int count = 0;
		if(n>=2){count++;}
		for(int i=1; i<n+1; i=i+2){
			if(p[i]){count++;}
			else if(prime(i)){count++; p[i]=true;}
		}

		cout << count << endl;
	}
}

C++: #include<iostream>
using namespace std;
int d[1000000]={},p[1000000]={};
void calc(){
	for(int i=2;i<1000000;i++){
		if(d[i]==0){
			for(int j=2;j<1000000;j++){
				if(i*j>1000000) break;
					d[i*j]=1;
			}
		}
	}
	for(int i=2;i<1000000;i++){
		if(d[i]==0)
		p[i]=p[i-1]+1;
		else
		p[i]=p[i-1];
	}
}
int main(){
	calc();
	int n;
	while(cin>>n,n){
		if(cin.eof())break;
		cout<<p[n]<<endl;
	}
	return 0;
}

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

int main()
{
  int i, j;
  int n;
  int ans;
  int count;

  ans = 0;

  cin >> n;
  for (i = 2; i <= n; i++){
    count = 0;
    for (j = 1; j <= i; j++){
      if (i % j == 0){
        count++;
      }
    }

    if (count == 2){
      ans++;
    }
  }
  cout << ans << endl;

  return (0);
}

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

bool prime[MAX_N];

void ini()
{
	for (int i = 2; i < MAX_N; i++)
	{
		if (prime[i])
			continue;
		else
		{
			for (int j = i * 2; j < MAX_N; j += i)
			{
				if (!prime[j] && j%i == 0)
					prime[j] = true;
			}
		}
	}
}

void solve()
{
	int ans, num;
	while (cin >> num)
	{
		ans = 0;
		for (int i = 2; i <= num; i++)
			if (!prime[i])
				ans++;
		cout << ans << endl;
	}
}

int main()
{
	ini();
	solve();
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a[1000001] = {0};
	for(int i = 0; i < 1000001; i++){
		a[i] = 1;
	}
	a[0] = 0;
	a[1] = 0;
	for(int i = 0; i < 100; i++){
		if(a[i]){
			for(int j = i * 2; j < 1000001; j += i){
				a[j] = 0;
			}
		}
	}

	int n;
	while(cin >> n){
		int k = 0;
		for(int i = 0; i <= n; i++){
			if(a[i]) k++;
		}
		cout << k << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	bool fl[1000001];
	memset(fl, true, sizeof(fl));
	for (int i = 2; i <= sqrt(num); i++) {
		if (fl[i]) {
			for (int j = 2; j*i <= num; j++) {
				fl[i*j] = false;
			}
		}
	}
	for (int i = 2; i <= num; i++) {
		if (fl[i]) {
			count++;
		}
	}
	return count;
}

int main() {

	int num = 0;
	while (cin >> num) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}