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 <cmath>
#include <iostream>

using namespace std;

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

	return true;
}

int main()
{
	int N[31];
	int C[31]; memset(N, 0, sizeof(N));

	for (int i = 0; i < 3; i++)
	{
		for (int j = 2; j <= N[i]; j++)
		{
			if (isprime(j) == true)
			{
				C[i] += 1;
			}
		}
	}

	for (int i = 0; i < 31; i++)
	{
		cout << C[i] << endl;
	}

	return 0;
}

C++: #include <stdio.h>

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

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,10000){
	bool flg = true;
	REP(j,primes.size()) if(i % primes[j] == 0 ) flg = false;
	if(flg) primes.PB(i);
    }

    int n;
    while(true){
	cin >> n;
	int res = upper_bound(ALL(primes),n) - primes.begin();
	cout << res << endl;
    }

    return 0;
}

C++: #include <stdio.h>

long check_prime(int a)
{
   long c;

   for ( c = 2 ; c <= a-1; c++ )
   {
      if ( a%c == 0 )
      {
	    return 0;
      }

   }
   if ( c == a )
      return 1;
}

int main ()
{
    long  n=0,i=0,prime=0,result=0;

    scanf("%ld",&n);

 for(i=2;i<=n;i++)
 {

   result = check_prime(i);

   if ( result == 1 )
     prime = prime +1;
 }

 printf("%ld",prime);
 printf("\n");
 return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX_N 999999
int main()
{
    int n;
    bool notPrime[MAX_N+2];
    int count[MAX_N+2];
    for (int i = 2 ; i <= MAX_N ; i++)
    {
        if (!notPrime[i])
        {
            for (int g = i+i ; g <= MAX_N ; g += i)
            {
                notPrime[g] = true;
            }
        }
    }
    int cnt = 0;
    count[1] = 0;
    for (int g = 2 ; g <= MAX_N ; g++)
    {
        if (!notPrime[g])
            cnt ++;
        count[g] = cnt;
    }
    while (cin >> n)
    {
        cout << count[n] << endl;
    }
    
}

C++: def sieve_prime(n): # return prime numbers within [1, n]
  primes = []
  is_prime = [True] * (n+1) # [0, n]
  for i in range(2, n+1):
    if not is_prime[i]:
      continue # need only primes

    primes.append(i)
    for j in range(i*2, n+1, i): # range(i*2, n+1, i) = {i*2, i*3, ...}
      is_prime[j] = False

    """
    Compare the above code with the below one in the view of time complexity
    for j in range(i*2, n+1):
      if j % i == 0:
        is_prime[j] = False
    """
        
  return primes
      
while True:
  try:
    n = int(input())
    print(len(sieve_prime(n))) # because T <= 30, you can simply use sieve_prime every time
  except EOFError:
    break

C++: #include<iostream>

using namespace std;

int main(){

int data[1000000];


 for(int i = 0; i < 1000000; i++) data[i] = 1;

 for(int i = 2; i*i < 1000000; i++){
   if(data[i] == 1){
     for(int j = i*2; j < 1000000; j+=i) data[j] = 0;
   }
 }
 int in;
 
 while(cin >> in){
   
   int sum = 0;
   for(int i = 2; i <= in; i++){
     if(data[i] == 1) sum++;
   }
   
   cout << sum <<endl;
 }
 return 0;
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

bool isPrime(int x) {
	for (int j = 2; j * j <= x; j++) {
		if (x % j == 0)
			return false;
	}
	return true;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)

bool prime[1000000];
int cou[1000000]={0};

int main(){
	int n;
	
	rep(i, 1000000) prime[i] = true;
	prime[1]=false;
	for(int i=1;i*i<1000000;i++){
		if(prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				prime[j]=false;
			}
		}
	}
	rep(i,999999){
		if(prime[i+1]) cou[i+1]=cou[i]+1;
		else cou[i+1]=cou[i];
	}
	while(cin>>n){
		cout<<cou[n]<<endl;
	}
	return 0;
}

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

int main(){
  
  int n,cnt = 0;

  while(cin >> n){
    int num[n] ={0};
    for(int i = 2; i  <= n; i++){
      if(num[i] == 0){
        for(int j = 1; j <(n/i); j++){
          num[i+(j*i)] = 1;
        }
        cnt++;
      }
    }
  cout << cnt << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<double, int>;

int main() {
    vector<bool> is_prime(1000000, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<is_prime.size(); ++i) {
        if(is_prime[i]) {
            prime.push_back(i);
            for(int j=i+i; j<is_prime.size(); j+=i) {
                is_prime[j] = false;
            }
        }
    }
    int n;
    while(cin >> n) {
        cout << upper_bound(prime.begin(), prime.end(), n) - prime.begin() << endl;
    }
}

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

int main()
{
 bool prime[1000000];
 for(int i=0; i<1000000; i++) prime[i] = true;

 prime[0] = prime[1] = false;
 for(int i=0; i<1000000; i++)
  if(prime[i]){
   for(int j=i+i; j<1000000; j += i)
    prime[j] = false;
  }

 int n;
 while(cin >> n){
  int c = 0;
  for(int i=0; i<=n; i++)
   if(prime[i]) c++;
  
  cout << c << '\n';
 }

 return 0;
}

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

bool t[1000000] = {};

int is_prime(int n) {
  int i;
 
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
 
  return true;
}

int main() {
  int n, i, r;
  n = 999999;

  for (i = 0; i < n; i++) {
    t[i] = is_prime(i);
  }

  while (cin >> n) {
    r = 0;
    for (i = 2; i <= n; i++) {
      if (t[i]) {
        r++;
      }
    }
    cout << r << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	if(x == 2){
 		return 1;
	}
	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 <cmath>
#include <vector>
using namespace std;

int main(){
    bool prime[1000000];
    int n;
    for(long int i=2;i<1000000;i++){
        bool isprime=true;
        for(long int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                isprime=false;
                break;
            }
        }
        prime[i]=isprime;
    }
    while(cin >> n){
        int cnt = 0;
        for(int i=2;i<=n;i++){
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}