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;
const int MAX=1000000;
bool t[MAX+1];
int c[MAX+1];

void make_table(){
	t[0]=t[1]=1;
  for(int i=0;i<=MAX;i++){
 	if(!t[i]){
 		for(int j=i+i;j<=MAX;j+=i)
 			t[j]=1;
 	}
  }
}
int main(){
  make_table();
  	int n; 
	for(int i=1;i<=MAX;i++){
		c[i]=(t[i])?c[i-1]:c[i-1]+1;
	}

	while(cin>>n)
		cout<<c[n]<<endl;
	
}

C++: #include<iostream>

int main(){

	bool data[100001];

	for (int i = 0; i < 100001; i++)
		if (i % 2 == 0)
			data[i] = false;
		else
			data[i] = true;

	int in;

	int res=0;

	for(int i=2;i<=100000;i++){
		if (i % 2 != 0) {
			for (int j = 2; j < i; j++) {
				if (i%j == 0) {
					data[i] = false;
					goto fl;
				}
			}
		}
	fl:;
	}

	while (true) {

		std::cin >> in;

		for (int i = 2; i <= in; i++) {
			if (data[i] == true)
				res++;
		}

		std::cout << res << std::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) {
	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 <iostream>
#include <algorithm>
using namespace std;

int prime_num(int n)
{
  ++n;
  bool* array = new bool[n];
  fill_n(array, n, true);
  array[0] = array[1] = false;

  for (int i = 2; i < n; ++i)
  {
    if (!array[i]) continue;
    for (int j = i * 2; j < n; j += i)
    {
      array[j] = false;
    }
  }

  int result = 0;
  for (int i = 0; i < n; ++i)
  {
    if (array[i]) ++result;
  }

  delete[] array;
  return result;
}

int main(void)
{
  int n;
  while (cin >> n)
  {
    cout << prime_num(n) << endl;
  }
  return 0;
}

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

int main(){
	int num;
	int count = 0;
	int i,j;

	cout << "数字を入力してください" << endl << "number :";
	cin >> num;

	for(i=2; i<num; i++){
		for(j=2; j<i; j++){
			if(i%j ==0){
				break;
			}
		}
		if(j == i){
			count++;
		}
	}
	cout << count << endl;
	cin >> num;
	return 0;
}

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

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=a^0.5;
      for(i=2; i<=a_sqrt; i++){
        for(j=past+1; j<=a; j++){
          if(j%i==0) chk[j]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

C++: #include <cstdio>
#include <cstring>
const int MAX_n = 999999;
bool isPrime[MAX_n+1];
int sum[MAX_n+1];
int main()
{
    memset(isPrime,true,sizeof(isPrime));
    for(int i = 2; 2*i <= MAX_n ; ++i)
        if(isPrime[i])
            for(int j = 2*i; j <= MAX_n; j+=i)
                isPrime[j] = false;
    isPrime[0] = isPrime[1] = false;
    
    for(int i = 0; i < MAX_n; ++i)
        sum[i+1] = sum[i] + isPrime[i+1];
    
    int n;
    while(scanf("%d",&n) != EOF)
    {
        int ans = sum[n];
        printf("%d\n",ans);
    }
    
}

C++: #include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=1000001;
bool p[MAXN];
vector<int> a;
int main(){
	memset(p,false,sizeof(p));
	for (int i=2;i<sqrt(MAXN);i++)
		for (int j=i+i;j<MAXN;j+=i)
			p[j]=true;
	for (int i=2;i<MAXN;i++)
		if (!p[i])
			a.push_back(i);
	int n;
	while (cin >> n){
		vector<int>::iterator f=lower_bound(a.begin(),a.end(),n);
		if (*f==n)
			cout << f-a.begin()+1 << endl;
		else
			cout << f-a.begin() << endl;
	}
	return 0;
}

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


using namespace std;

int main() {
	vector<int> prime_num{ 2, 3 };
	int n;

	while (cin >> n){
		int result;
		if (n <= 1) {
			result = 0;
		}
		else if (n == 2){
			result = 1;
		}
		else if (n < prime_num.back()){
			result = count_if(prime_num.begin(), prime_num.end(), [n](int a){return a <= n; });
		}
		else {
			for (int i = prime_num.back() + 2; i <= n; i += 2) {
				if (all_of(prime_num.begin(), prime_num.end(), [i](int a){return (i % a) != 0; })) {
					prime_num.push_back(i);
				}
			}
			result = prime_num.size();
		}


		cout << result << endl;javascript:void(0)
	}


	return 0;
}

C++: /*
 0…未確定
 1…素数
 2…素数でない
*/
#include <iostream>

using namespace std;

int main(){
    int num[1000000]={0}, b, a, n, c;
    for(int i=2;i<=1000;i++){
        if(num[i]==0){
            num[i]=1;
            b=1;
            while((a=(++b*i))<1000000) num[a]=2;
        }
    }
    
    while(cin >> n){
        c=0;
        for(int i=2;i<=n;i++) {
            if(num[i]==1) c++;
        }
        cout << c << endl;
    }
    return 0;
}

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; i++)
	{
		Counter += CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (IsPrime(N))
		return 1;

	return 0;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int n;
    int p = 0;
    
    cin >> n;
    
    for(int x=n; x>=1; x--)
    {
            int c = 0;
            for(int y=1; y<=x; y++)
            {
                    if(x%y==0)
                    c++;
            }
            
            if(c==2)
            {
                    cout << x << endl;
                    p++;
            }
    }
    
    cout<< p << endl;
    

return 0;
}

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

int main() {
	int N;
	while (cin >> N) {
		vector<int> v(N + 1, 1);
		v.at(0) = 0;
		v.at(1) = 0;

		int r = sqrt(N);
		for (int i = 2; i <= r; i++) {
			int& p = v.at(i);
			if (p == 1) {
				for (int j = i*2; j <= N; j+=i) {
					int& p2 = v.at(j);
					if (!(j % i)) {
						p2 = 0;
					}
				}
			}
			else {
				continue;
			}
		}

		int c = count(v.begin(), v.end(), 1);
		cout << c << endl;
	}
}

C++: #include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

#define N 1000005

bool isPrime [N];

void seive()
{
    memset(isPrime, true, sizeof N);

    isPrime [0] = isPrime [1] = false;

    for ( int i = 4; i < N; i += 2 )
        isPrime [i] = false;

    int squareRoot = (int) sqrt (N);

    for ( int i = 3; i <= squareRoot; i += 2 ) {
        for ( int j = i * i; j < N; j += i )
            isPrime [j] = false;
    }
}

int main(int argc, const char * argv[])
{
    seive();

    int n;

    while ( scanf ("%d", &n) != EOF ) {
        int ans = 0;

        for ( int i = 2; i <= n; i++ ) {
            if (isPrime [i]) ans++;
        }

        printf ("%d\n", ans);
    }

    return 0;
}