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 := 3; i <= num; i += 2 { //1を除く入力値以下の数字
			for j := 3; j < i; j += 2 {
				if i%j == 0 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count + 1)
	}
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

using namespace std;

int main()
{
    int n;

    while (cin>>n){
        int count=0;

        if(1<n){
            count++;
        }
        if(n%2==0){
            n--;
        }
        while (1 < n){
            int prime_flag=1;
            for (int j = 2; prime_flag && j < n; j++) {
                if(n % j == 0){
                    prime_flag=0;
                }
                if(2 < j){
                    j++;
                }
            }
            count+=prime_flag;
            n-=2;
        }
        cout<<count<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int count=0;
		for(int i=5;i<=n;i+=6){
			int j=5;
			while(true){
				if(i%j==0)
					break;
				if(j>(int)sqrt((double)i)){
					count++;
					break;
				}
				j+=2;
			}
		}
		for(int i=7;i<=n;i+=6){
			int j=5;
			while(true){
				if(i%j==0)
					break;
				if(j>(int)sqrt((double)i)){
					count++;
					break;
				}
				j+=2;
			}
		}
		cout<<count+1<<endl;
	}
	return 0;
}

C++: import java.util.Scanner;
import java.io.*;
class Main{
    public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int ans,n;
    while(sc.hasNext()){
    	n=sc.nextInt();
    	ans=0;
    	if(n==1)ans=-1;
    	for(int i=1;i<=n;i+=2){
    		int flag=0;
    		for(int j=3;j<=Math.sqrt(i);j+=2){
    			if(i%j==0){
    				flag=1;break;
    			}
    		}
    		if(flag==0)ans++;
    	}
    	System.out.println(ans);
    }
    }
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int max[30], sol[30], listID=0;
	
    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        min = 1;
        minID = 0;
		printf("check %d ->", n);
        for (int i=0; i<listID; i++){
            if (max[i] < n && min <max[i]){
                min = max[i];
				cnt = sol[i];
            }
        }
		printf("check  %d - %d (cur sols = %d)\n", min+1, n, cnt);
        for (int i=min+1; i<=n; i++){
            if (IsPrime(i)) cnt++;
        }
        max[listID] = n;
        sol[listID] = cnt;
        listID++;
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			if(isprime(i))c++;

		}
		printf("%d\n",c);
	}
	return 0;
}

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

int main(){

	const int N_MAX=100;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		count[i]=so[i]=0;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=1;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]>0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=1;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+1-so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int yakusuu(int i){
	int counter=0;
	for (int j = 1; j <= i; j++){
		if (i%j == 0) counter++;
	}
	return counter;
}


int main()
{
	int n;
	
		
		while (scanf("%d",&n)!=-1)
		{
			int counter1 = 0;
			for (int i = 0; i <= n; i++)
			{
				if (yakusuu(i) == 2) counter1++;
			}

				cout << counter1 << endl;
		}
		
		
	return 0;
}

C++: int primes[78498], num_primes;
int calculated;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	calculated = 2;
	num_primes = 1;
	while (true) {
		int n;
		if (!scanf_s("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				int max = (int)(sqrt(i)) + 1;
				for (int j=1; primes[j] < max&&j<num_primes; j++) {
					if (i%primes[j] == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

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

int main(){

	bool pn[1000010];
	int sum[1000010] = {0};
	int n;
	
	for(int i = 0; i <= 1000000; i++) {
		pn[i] = true;
	}
	
	pn[1] = false;
	for(int i = 1; i <= 1000000; i++) {
		if(!pn[i]) continue;
		for(int j = 2; i*j <= 1000000; j++) {
			if(pn[i*j]) pn[i*j] = false;
		}
	}
	
	for(int i = 1; i <= 1000000; i++) {
		sum[i] = sum[i-1] + pn[i];
	}
	
	while(cin >> n) {
		cout << sum[n] << endl;
	}

    return 0;
}

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

int main()
{
	int n;
	while(cin >> n)
	{
		int i,j;
		int k = 0;
		for (i=2; i<=n; i++)
		{
			int c=0;
			for(j=1; j<=n; j++)
			{
				if(i%j == 0)
				{
					c++;
				}
			}
			if (c == 2)
			{
				k++;
			}
		}
		cout << k << endl;
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int N = 1000000;
int main(){
	int n;
	vector<bool> v(N,true);
	v[0] = false;
	v[1] = false;
	for (int i=2; i<N; ++i){
		if (v[i] == true){
			for (int j=2*i; j<N; j+=i){
				v[j] = false;
			}
		}
	}
	vector<int> cnt(N);
	for (int i=2; i<N; ++i){
		if (v[i]) cnt[i] = cnt[i-1]+1;
	   else cnt[i] = cnt[i-1];
	}
	while (cin >> n){
		cout << cnt[n] << '\n';
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
    int n,i,k,j,b=0;

    cin >> n;

     for(i=2; i<=n; i++)
    {
        k = 1;
        for(j=2; j<=i/2; j++)
        {
            if(i%j==0)
            {
                k = 0;
                break;
            }
        }

        if(k==1)
        {
            b++;
        }
    }

    cout << b << endl;

    return 0;
}

C++: #include<iostream>
int main() {

  int n,i,j,c;
  while(std::cin>>n){
    c=0;
    int list[n-1];
    for(i=2;i<n+1;i++)list[i-2]=i;
    for(j=2;j*j<n+2;j++)
      if(list[j-2]!=0)
	for(i=1;j-2+list[j-2]*i<n;i++)
	  list[j-2+list[j-2]*i]=0;
    for(i=0; i<n-1; i++)
      if(list[i]!=0)c++;

    std::cout<<c<<"\n";
  }
}

C++: #include <stdio.h>

int main(){
	long sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z,d=0;
	while (scanf("%d", &n) != EOF){
		z = 0;
		if(d < n)
		{for (i = 3; i < n; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++; d = i; }
			}
		}
	}
		for (i = 0; i < n; i++){ if (sosuu[i] > n + 1)break; z++; }printf("%d\n", z);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int i,n,k;
	
	while(cin >> n){
		int flug[n+1];
		int count = 0;
		for(i=0;i<n+1;i++) flug[i] = 1;
		// 0, 1は除外
		flug[0] = flug[1] = 0;
		for(i=2;i*i<n;i++){
			for(k=n;k>=2;k--){
				if((k % i == 0) && (k != i)){
					flug[k] = 0;
				}
			}
		}
		
		// 個数を走査
		for(i=2;i<n+1;i++){
			if(flug[i] == 1){
				count++;
			}
		}
		
		cout << count << endl;
	}
	return 0;
}