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 <stdio.h>

int isPrime(int n);

int main(void){
    int n;
    int cnt;

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

    return 0;
}


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

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



bool IsPrime[1000010];  //保证不做素数的倍数
int Prim[1000010];   //存素数
void euler_prime(int n){
    int num = 0, j;
    for(int i = 2; i <= n; i ++){
        if(!IsPrime[i])   //不是目前找到的素数的倍数    1不是素数
            Prim[num ++] = i;  //记录质数
        for(j  = 0; j < num; j ++){
            if(i * Prim[j] > n)
                break;
            IsPrime[i * Prim[j]] = true;  //筛;//找到的素数的倍数不访问
            if(i % Prim[j] == 0)
                break;  //i可以看做prime[j]*某个数， i*prime[j+1]就可以看做 prime[j]*某个数*prime[j+1] 。而 prime[j] 必定小于 prime[j+1]，所以 i*prime[j+1] 必定已经被 prime[j]*某个数 筛掉，就不用再做了（等到i=6即最大合因子时会筛掉）
        }
    }
}

int setans(int x)
{
    int cnt = 0;
    for(int i=2; i<=x; i++) {
        if(!IsPrime[i])
            cnt++;
    }
    return cnt;
}
int main()
{
    int n;
    euler_prime(1000005);
    while(scanf("%d",&n))

        printf("%d\n",setans(n));

    return 0;
}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<'\n';}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;
tag:m[i]=e;}}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}


vector<int> primes(100000);
int num_prime = 0; 

bool IsPrime(int m){
    if(m<2) return false;
    if(m==2) return true;
    if(m%2==0) return false;

    double root_m = sqrt(m);

    for(int i=3; i<=root_m; i+=2){
        if(m%i==0) return false;
    }

    return true;
}

void updatePrimes(int st, int max_v){
    for(int i=st;i < max_v+1; i+=2){
        if(IsPrime(i)){
            num_prime++;
            primes[num_prime] = i;
            // printf("%dは素数 ", i);
        }
    }
}
 
int main()
{
    primes[0] = 0;
    primes[1] = 2;
    primes[2] = 3;
    num_prime = 2;
    updatePrimes(5, 1000000);
    int num, id;

    while(scanf("%d", &num) != EOF){
        auto it = lower_bound(primes.begin(), primes.begin()+num_prime, num);
        if(*it > num) it--;
        id = it - primes.begin();
        printf("%d\n", id);
    }
    return 0;
}

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

#define MAX 1000000

int main(){
	bool p[MAX+1];
	int num,answer;

	while( scanf("%d" , &num) != EOF ){	
		// ツ陛渉青板づ個渉可甘コツ可サ
		p[0] = false;
		p[1] = false;
		for(int i=2 ; i<=MAX ; i++){
			p[i] = true;
		}
		answer = 0;

		//ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
		for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
			if(p[i]==1){
				for(int j=i*2; j<=MAX; j=j+i){
					p[j] = false;
				}
			}
		}

		// Output
		for(int i=0; i<=num; i++){
			if(p[i]){
				answer++;
			}
		}
		printf("%d\n", answer);
	}
}

C++: #include<cstdio>
#include<cstring>
int main(){
	int a,b,d;
	while(~scanf("%d",&a)){
		int c[a+1];
		memset(c,0,sizeof(c));
		d=0;
		for(b=2;b<=a;b++){
			if(c[b]==0){
				d++;
				for(int i=b;i<a+1;i+=b)	c[i]=1;
			}
		}
		printf("%d\n",d);
	}
}

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

using namespace std;

int furui(int N){
  int i;
  int count=0;
  int array[1000000];
  array[0]=false;
  array[1]=false;
    
  for(i=2;i<=N;i++){
    array[i]=true;
  }

  for(i=2;i<=N;i++){
    if(array[i]==true)for(int j=i*i;j<=N;j+=i){
	array[j]=false;
      }
  }

  for(i=2;i<=N;i++){
    if(array[i]==true)count++;
  }

  return count;
}

int main(){
  int cnt=0,n;
  while(cnt<30){
    cnt++;
    cin >> n;
    cout << furui(n) <<endl;
}

  return 0;
}

C++: #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;

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

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}


int main(void){
	int n;
	while(scanf("%d", &n)){
		if(n == 'EOF') break;
		cout << sieve(n) << '\n';
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

    int n;
    while (~scanf("%d", &n)) {
        for (int i = 2; i * i <= n; ++i) {
            if (!a[i]) continue;
            for (int j = i + i; j <= n; j += i) a[j] = false;
        }
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

C++: #include <stdio.h>

int main(int argc, const char * argv[])
{
    int i, j, k, n, count;
    int a[999999];
    
    count = 0;
    
    while(scanf("%d",&n) != EOF){
        if (count == 0) {
            if (n > 1) {
                a[count++] = 2;
                if (n > 2) {
                    a[count++] = 3;
                    for(i=5; i<=n; i+=2){
                        k=0;
                        for(j=0; a[j]*a[j] <= i; j++){
                            if(i%a[j] == 0) {
                                k = 1;
                                break;
                            }
                        }
                        if (k == 0) {
                            a[count++] = i;
                        }
                    }
                }
            }
            printf("%d\n",count);
        } else {
            if (n <= a[count - 1]) {
                for (i=count - 1; n < a[i]; i--);
                printf("%d\n", i+1);
            } else {
                if (a[count-1] == 2) {
                    a[count++] = 3;
                    printf("%d\n",count);
                } else {
                    for(i=a[count - 1]+2; i<=n; i+=2){
                        k=0;
                        for(j=0; a[j]*a[j] <= i; j++){
                            if(i%a[j] == 0) {
                                k = 1;
                                break;
                            }
                        }
                        if (k == 0) {
                            a[count++] = i;
                        }
                    }
                    printf("%d\n", count);
                }
            }
        }
    }
    return 0;
}