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 <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,i,j;
    int ans;

    while(cin >> n){ 
        ans=0;
        for(i=2;i<=n;i++){
            for(j=2;j<=i;j++)
                    if(i%j==0){
                        
                        //nの因数iが素数かどうかを判定する
                        //割り切れたら素数じゃないのでループ抜ける
                        
                        break;

            }
                    //jが最終まで行けばiが素数なのでans++
                    if(j==i)ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int n;
int a[1000000];
int ans;

int main()
{
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            if(i == 2 || i == 3 || i == 5 || i == 7)ans++;
            if(i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0)ans++;
        }
        cout << ans << endl;
        ans = 0;
    }
    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) {
	if (x % 2 == 0)
		return true;
	for (int j = 3; j * j <= x; j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

C++: #include<memory.h>
#include<cstdio>
const int maxn=100000;
int x;
bool isPrime[maxn];
void generateprime()
{

    memset(isPrime,true,sizeof(isPrime));
    for(int i=2;i<maxn;i++)
        for(int j=2;j*i<maxn;j++)
        isPrime[j*i]=false;
}

int main()
{
    generateprime();
    while(scanf(" %d",&x)!=EOF)
    {   int res=0;
        for(int i=2;i<=x;i++)
            if(isPrime[i])
            {
            res=res+1;}
        printf("%d\n",res);
    }
}

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

bool isPrime(unsigned int n) {
  unsigned int count=0;
  unsigned int max;
  count = 0;
  max = n;

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

int main() {
  unsigned int input;
  unsigned int count;
  unsigned int cum[500000]; // for odd numbers greater than or equal to 1

  count = 1; // For 2
  cum[0] = 0; // For 1
  cum[1] = 2; // For 3
  for(int i= 2; i<500000; i++) {
    if(isPrime(2*i+1)) {
      cum[i] = cum[i-1]+1;
      count++;
    } else {
      cum[i]=cum[i-1];
    }
  }

  while(cin >> input) {
    count = 0;
    if(input==2)
      cout << "1" << endl;
    else
      cout << cum[(int)(input-0.5)/2] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

vector<int>soe(int n);

int main(void)
{
	int num, pn;
	int count = 0;
	
	while(cin >> num){
		vector<int>test(num);
		test = soe(num);
		
		for(int i = 0; i < num; i++){
			if(test[i])
			count++;
		}
		cout << count <<endl;
	}
	return 0;
}

vector<int>soe(int n){
	vector<int>hyo(n);
	for(int i = 2; i < n; i++)
	hyo[i] = i;
	for(int i = 2; i*i < n; i++){
		if(hyo[i])
		for(int j = i*i; j < n; j += i){
			hyo[j] = 0;
		}
	}
	return hyo;
}

C++: #include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

int main()
{
    int prime_num[1000001];
    memset(prime_num, 0, 1000001);
    prime_num[2] = 1;
    int ans = 1;
    for(int i = 3; i <= 1000000; i++) {
        if(i % 2 == 0) { 
            prime_num[i] = prime_num[i-1];
            continue;
        }
        bool is_prime = true;
        for(int j = 3; j*j <= i; j++) {
            if(i % j == 0) {
                is_prime = false;
                break;
            }
        }
        if(is_prime) {
            prime_num[i] = prime_num[i-1] + 1;
        } else {
            prime_num[i] = prime_num[i-1];
        }
    }
    int n;
    while(cin >> n) {
        cout << prime_num[n] << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,j,o=0;
	bool n[1000000];
	for(int i=2;i<=99999;i++){
		n[i]=true;
	}
	n[0]=n[1]=false;
		for( j=2;j<=99999;j++){
			if(n[j]){
				for(int k=j*2;k<=99999;k+=j){
				n[k]=false;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
	o=0;
		}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <utility>
#include <string>
#include <math.h>
typedef unsigned long ul;

using namespace std;

int arr[1000000] = {0};

int main(){
	for(int i = 2; i < 999999; i++)arr[i] = 1;
	for(int i = 2; i*i < 999999; i++){
		for(int j = i*2; arr[i] == 1 && j <= 999999; j += i){
			arr[j] = 0;
		}
	}
	for(int i = 1; i <= 999999;i++)arr[i] += arr[i-1];

	int n;
	while(cin >> n){
		cout << arr[n] << endl;
	}
}

C++: #include <stdio.h>
int main(){
    bool prime[1000000];
    int n,ans;
    prime[2]=true;
    for(int i=3;i<1000000;i+=2)prime[i]=true;
    for(int i=3;i<=1000;i+=2){
        if(prime[i]){
            for(int j=i*i;j<1000000;j+=i)
                prime[j]=false;
        }
    }
    while(scanf("%d",&n)!=EOF){
        ans=0;
    for(int i=2;i<=n;i++)if(prime[i])ans++;
        printf("%d\n",ans);
    }
}

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

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

C++: #include <iostream>
using namespace std;
int main(){
    int n,count=0;
    while(cin>>n){
        count=0;
        for(int a=2;a<=n;a++){
            for(int b=2;b<=a;b++){
                if(a==b)count++;
                if(a%b==0)break;
            }
        }
        cout<<count<<endl;
    }
}