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>
#include <vector>

using namespace std;

int main(){
  int i;
  int count;
  vector<int> ans;
  bool flag;

  while(cin >> i){
    if(cin.eof()){
      break;
    }
    count = 0;
    for(int d = 2; d <= i; d++){
      flag = true;
      for(int dd = 2; dd < d; dd++){
	if(d%dd == 0){
	  flag = false;
	  break;
	}
      }
      if(flag){
	count++;
      }
    }
    ans.push_back(count);
  }
  for(int& d : ans){
    cout << d << endl;
  }

}

C++: #include<cstdio>
int n,ans;
bool p[1000005]={1,1};
int main()
{
	int i,j;
	for(i=2;i<=997;i++)
		if(!p[i])
			for(j=i;j*i<1000000;j++)
				p[j*i]=1;
	while(~scanf("%d",&n))
	{
		ans=0;
		for(i=2;i<=n;i++)
			if(!p[i]) ans++;
		printf("%d\n",ans);
	}
}

C++: #include<stdio.h>
#include<math.h>
int solve(int n,int start,int end);
int nextprime(int n);
int prime[500000];
int getprime(void);
int main(void)
{
	int n;
	int all = getprime();
	while (scanf("%d", &n) == 1)
	{
		
		printf("%d\n",solve(n,0,all)+1);
	}
}
int solve(int n,int start,int end)
{

	if (end == start)
	{
		if (n < prime[end])
			return end - 1;
		else return end;
	}
	int k = (end + start) / 2;
	if (n < prime[k])
		return solve(n, start, k-1);
	if (n > prime[k])
		return solve(n, k+1, end);
	return k;
}
int nextprime(int n)
{
	for (int i = n + 1;; i++)
	{
		int pan=1;
		for (int k = 2; k <= sqrt(i); k++)
		{
			if (i%k == 0)
			{
				pan = 0;
				break;
			}
		}
		if (pan)
			return i;
	}
}
int getprime(void)
{
	int i = 1, n = 0;
	while ((i = nextprime(i)) < 999999)
	{
		prime[n] = i;
		n++;
	}
	return n-1;
}

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

using namespace std;

int count = 0;

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

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


    return 0;
}

C++: #include<iostream>

int main(){
  int prime[1000000]={0};
  int number[1000000];
  int k,n;

  number[1] = 0;

  for(int i=2;i<1000000;i++){
    if(prime[i]==0){
      for(int j=2;i*j<1000000;j++){
        prime[i*j] = 1;
      }
    }
    if(prime[i]==0){
      number[i] = number[i-1] + 1;
    }else{
      number[i] = number[i-1];
    }
  }
  while(std::cin >> n){
    std::cout << number[n] << std::endl;
  }
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,z,x;
	
    scanf("%d",&n);

	for(i=2;i<=n;i++){
        z=0;
		for(j=2;j<=i;j++){
		    if(i%j==0 && i!=j){
			    z++;
				break;
			}
		}
		if(z==0){
		    x++;
		}
	}
	printf("%d\n",x);
	return 0;
}

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

int main(){
	int t;
	while(cin >> t){
		cerr << t << endl;
	}
}

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

int main() {
	int n,i,j,ans;

	while(cin >> n){
	ans=0;
			for(i=2; i<=n; i++){
				for(j=2; j<=i; j++){
					if(i % j == 0 && i != j) break;
						if(i == j) ans++;
			}
		
		}
		cout << ans << endl;
	}

	return 0;
}

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

//素数かどうか判定する関数
bool judge( int x )
{

    for( int i = 2; i <= sqrt(x); i++ )       //与えられた数の平方根までに含まれる素数で
    {                                         //割り切ることが出来たらなら、その数は素数ではない
        if( x % i == 0)
            return false;
    }

    return true;
}

int main()
{
    int n;

    while( cin >> n )                           //2が素数であることを予め考慮
    {
        int count = 1;                          //countは素数の数なので、1

        if( n <= 1 )                            //nが1以下なら素数の数は0
        {
            count = 0;
        }

        for( int i = 3; i <= n; i += 2 )        //3以上の自然数について、奇数のみ素数判定を行う
        {
            if( judge(i) )
                count++;
        }

        cout << count << endl;
    }

    return 0;
}

C++: #include<stdio.h>
const int MAX_N = 1000000;
int n;
int num[MAX_N];
int ans=0;

int main(){

    for (int i = 2; i < MAX_N; i++){
        num[i] = 1;
    }
    for (int i = 2; i < MAX_N; i++){
        if (num[i] == 0) continue;
        for (int j = 2; i*j < MAX_N; j++){
            num[i*j] = 0;
        }
    }

    while(scanf("%d",&n) != -1){
        ans = 0;
        for(int i = 0; i < n+1; i++){
            if(num[i] == 1){
            ans++;
        }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

#define N 1000000L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = 1000;
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = (long int) divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    std::cout << count << std::endl;
    if(c == EOF) break;
  }
  return 0;
}

C++: #include<stdio.h>
#include<math.h>
int main()
{
    long long int n,i,j,k,l,number[1000000];

    while(scanf("%lld",&n)!=EOF)
    {
       if(n==0 || n==1) printf("0\n");
       else if(n==2) printf("1\n");
       else if(n==3) printf("2\n");
       else
       {
            k=sqrt(n);
            l=1;
            for(i=0;i<n;i++)
            {
                number[i]=i+1;
            }

            for(j=2;j<=k;j++)
            {
                for(i=1;i<n;i++)
                {
                    if(number[i]%j==0)
                    {
                        number[i]=0;
                    }
                }
            }
            for(i=1;i<n;i++)
            {
                if(number[i]!=0) l++;
            }
            printf("%lld\n",l);
        }
    }
    return 0;
}

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

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

bool pr(int p){
    int x=2;
    while(x*x<=p){
        if(p%x==0){
            return false;
        }
        x++;
    }
    return true;
}


int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for(int i=2;i<=n;i++){
            if(pr(i)){
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}