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++: #include <iostream>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
        if(n==1)cout<<"0"<<endl;
        else if(n==2)cout<<"1"<<endl;
        else {
          for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=j;i+=2){
				if(j%i==0)k++;
		        }
		     if(k==1)kk++;
		   }
             }
       cout<<kk+1<<endl;
	   }
	return 0;
	}

C++: #include <stdio.h>
#define MAX 10^6

int main(void)
{
	int n,ans,i,k,j=0;
	int ansbox[MAX];

	for(i=2 ; i<MAX ; i++){
		for(k=2 ; k<=i ; k++){
			if(i%k==0)
				break;
		}
		if(i==k){
			ansbox[j]=k;
			j++;
		}
	}

	while(scanf("%d",&n) != EOF){
		for(i=2 ; i<=n ; i++){
			if(ansbox[i]<=n)
				ans++;
		}
		printf("%d",ans);
		ans=0;
	}
	
	return 0;
}

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

int main(){
	bool is_prime[1000000];

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];

	int cnt=0;
	for(int i=0;i<1000000;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>
#include <vector>
#define N 1000000
using namespace std;

int main(void){
	int n;
	int i,j;
	int count;
	vector<int> prime(N);

	for(i=0;i<N;i++){
		if(i%2==0||i==1) prime.at(i)=0;
		else prime.at(i)=1;
	}
	prime.at(2)=1;
	for(i=3;i<(N/2);i+=2){
		if(prime.at(i)==1){
			for(j=2;i*j<N;j++){
				prime.at(i*j)=0;
			}
		}
	}
	while(cin >> n){
		count=0;
		for(i=2;i<=n;i++){
			if(prime.at(i)==1) count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int f[1000000];

signed main(){
    fill_n(f,1000000,1);
    f[0]=f[1]=0;
    for(int i=2;i<1000000;i++){
        if(!f[i])continue;
        for(int j=i+i;j<1000000;j+=i)f[j]=0;
    }
    for(int i=1;i<1000000;i++)f[i]+=f[i-1];

    int n;
    while(cin>>n)cout<<f[n]<<endl;
    return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
bool isPrime(int n)
{
    for(int i = 2; i * i <= n; i ++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        int res = 0;
        for(int i = 2; i <= n; i ++)
        {
            if(isPrime(i))
            {
                res ++;
            }
        }
        printf("%d\n",res);
    }
    return 0;
}

C++: import java.io.*;

import java.util.*;
import java.math.*;



class Main{

	private static ArrayList<Integer> sum_check(int a){

		int count = 0;
		ArrayList<Integer> s = new ArrayList<Integer>();
		
		for(int i=0;i<=a;i++){
			s.add(0);
		}
		s.set(2,1);
		for(int i=3;i<=a;i=i+2) s.set(i,1);
		for(int i=3;i<=Math.sqrt(a);i=i+2){
			if(s.get(i) == 0) continue;
			for(int j=i+i;j<=a;j=j+i)s.set(j,0);
		}		
		return s;

	}

	

		public static void main(String args[]) throws IOException{

			Scanner scan = new Scanner(System.in);

			int n,count;
			ArrayList<Integer> a = new ArrayList<Integer>();

			ArrayList<Integer> res = new ArrayList<Integer>();


			while(scan.hasNext()){
				count = 1;

				String str1 = scan.next();

				n = Integer.valueOf(str1).intValue();

				if(n != 1){
				a = sum_check(n);
				for(int i=3;i<=n;i=i+2){
					if(a.get(i) == 1)count++;
				}
				res.add(count);
				}
				else res.add(0);

			}
			for(int i=0;i<res.size();i++){
				System.out.println(res.get(i));
			}

		}

}

C++: #include<iostream>
#include<stdio.h>
#define M 1000000
using namespace std;
int a[M]={0};
int main()
{
    int n,i,j,k=0,l;

    a[0]=1;
    a[1]=1;
    for(i=2;i<=M;i++){
        for(j=2;i*j<M && a[i]!=1;j++){
            a[i*j]=1;
        }
    }
    while(cin>>n)
    {
        k=0;


    for(i=1;i<=n;i++){
        if(a[i]==0)k++;
    }
    cout<<k<<endl;
    //k=0;
    }



    return 0;
}

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

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

int cntPrime(int n) {
  int cnt = 0, i, k;
  for(i = 2; i <= n; i++) {
    cnt += prime(i);
  }
  return cnt;
}

int main() {
  int a;
  int arg[1024] = { 0 };
  int cnt = 0;
  while(scanf("%d", &a) != EOF) {
    printf("%d\n", cntPrime(a));
  }
  int i;
  for(i = 0; i < cnt; i++) {
  }
}

C++: #include <iostream>
int main(int argc, const char * argv[])
{

    // insert code here...
    
    while(true)
    {
        int n;
        std::cin >> n;
        if(std::cin.eof())break;
        
        int count = 0;
        std:
        for(int i=2;i<n;i++)
        {
            bool flag = true;
            for(int j=2;j<i/j+1;j++)
            {
                if(i%j==0)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                count++;
            }
        }
        
        std::cout << count <<"\n";
        
    }
    
    return 0;
}

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

int prime[1000000];


bool isPrime(int n) {
  int x = (int)sqrt(n);
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define N 500000
using namespace std;

int main(){

  int n;
  int a,b,i;
  int sosu[N];
  bool judge;

  sosu[0] = 2;
  for(a=3,i=1;a<1000000;a++){
    judge = true;
    for(b=0;sosu[b]*sosu[b] <= a;b++){
      if(a%sosu[b] == 0){
	judge = false;
	break;
      }
    }
    if(judge){
      sosu[i] = a;
      i++;
    }
  }
  while(cin >> n){
    if(0<n && n<1000000){
      for(i=0;sosu[i]<=n;i++);
      cout << i << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;
	while(cin >> n){
		count = 0;
		for(int i = 1; i <= n; i++){
			if(i < 2);
			else if(i == 2){
				count++;
			}
			else if(i % 2 != 0){
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
						break;
					}
				}
				if(flag != true){
					count++;
				}
				flag = false;
			}
		}

		cout << count << endl;

	}

	return 0;
}