Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	a, _ := strconv.Atoi(scanner.Text())
	return a
}

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

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

int main(){
   int i,j,n,flag=0,x=1;
   int sosu[999];
   sosu[0] = 2;
   cin>>n;
   for(i=3;i<=n;i++){
      flag = 0;
      
      for(j=0;j<x;j++){
         if(i%sosu[j] == 0){
            flag++;
            break;
         }
      }
      if(flag == 0){
         sosu[x] = i;
         x++;
      }
   }
   printf("%d\n",x);
   return 0;
}

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

typedef unsigned int Int;

Int sqrt_prm(const Int& target, Int x = 0) {
	while (x*x < target) {
		x++;
	}
	return x;
}

int main() {
	while (not std::cin.eof()) {
		Int target;
		std::cin >> target;

		std::vector<Int> primes = {};
		Int sqrt = 0;
		for (Int n = 3; n <= target; n+=2) {
			bool flag = true;

			sqrt = sqrt_prm(n, sqrt);
			for (auto&& div : primes) {
				if (n > sqrt) { break; }
				if (n % div == 0) {
					flag = false;
					break;
				}
			}

			if (flag) {
				primes.push_back(n);
			}
		}

		std::cout << primes.size() + (target >= 2 ? 1 : 0) << std::endl;
	}
}

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 + 1)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

using namespace std;

const int Max=1000007;

bool visit[Max];
int prime[Max];
int num=0;
void init_prim()
{
    memset(visit, true, sizeof(visit));
    for (int i = 2; i <Max; ++i)
    {
        if (visit[i] == true)
        {
            num++;
            prime[num] = i;
        }
        for (int j = 1; ((j <= num) && (i * prime[j] <= 1000000));  ++j)
        {
            visit[i * prime[j]] = false;
            if (i % prime[j] == 0) break;
        }
    }
}

int main()
{
    int n;
    init_prim();
    while(~scanf("%d",&n))
    {
        int l=lower_bound(prime,prime+num,n)-prime;
        if(prime[l]>n)
            l=l-1;
        printf("%d\n",l);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <stdio.h>
using namespace std;

// Prime Number(0009(
int main()
{
	const int MAX = 1000000 + 1000;
	static bool prime[MAX];
	for (int i = 0; i < MAX; ++i)
		prime[i] = true;
	prime[0] = prime[1] = false;

	for (int i = 2; i < MAX; ++i) {
		if (prime[i]) {
			for (int j = i+i; j < MAX; j += i)
				prime[j] = false;
		}
	}

	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (prime[i])
				++ans;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#define ll long long
using namespace std;
bool status[1000000];
int prime[1000000];
 int N=1000000;
void siv()
{
    int sq=sqrt(N);
    for(int i=4;i<=N;i+=2)status[i]=1;
    for(int i=3;i<=sq;i+=2)
    {
        if(status[i]==0)
        {
            for(int j=i*i;j<=N;j+=i)status[j]=1;
        }
    }
    status[1]=1;
}
void res()
{
    int ans=0;
    for(int i=1;i<=N;i++)
    {
        if(status[i]==0)ans++;
        prime[i]=ans;
    }
}
int main()
{
    siv();
    res();
    int x;
    scanf("%d",&x);
    printf("%d\n",prime[x]);
    return 0;

}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<queue>
#include <sstream>
#include<string.h>
#include<math.h>
using namespace std;
int prime[1000005];
bool is_prime[1000005];
int seve(int n)
{
    int p=0;
    for(int i=0;i<=n;i++)
        is_prime[i]=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;
        }
    }
    return p;
}
int main(void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",seve(n));
    }
    return 0;
}

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

using namespace std;

bool p[3000000];
vector<int> prime;

void init(){
    memset(p,1,sizeof(p));
    p[0] = p[1] = false;
    for(int i = 2; i <= 1000000; i++){
        if(!p[i]) continue;
        for(long long j = 1LL*i*i; j <= 1000000; j += i)
            p[j] = false;
        prime.push_back(i);
    }
}

int CntPrime(int n){
    //vector<int>::iterator it = lower_bound(prime.begin(), prime.end(), n);
    //if( *it > n) it--;
    //return (it - prime.begin() + 1);
    int res = 0;
    for(int i = 0; i < prime.size(); i++){
        if(prime[i] <= n) res++;
        else break;
    }
    return res;
}

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

C++: #include <iostream>

using namespace std;

int main(){
	int n , ans = 1;

	cin >> n;

	if(n <= 1){
		ans--;
	}

	for(int i = 2; i <= n; i++){
		if(i % 2 != 0 && 9 > i){
			//cout << i << endl;
			ans++;

		}if(i >= 9){
			if(i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0){
				//cout << i << endl;
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

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

int main(){
  int a,j,cou;
  while(cin>>a){
    cou=0;
    for(int i=2;i<=a;i++){
      if(i==2){
	cou++;
	continue;
      }
      else if(i%2==0)continue;
      for(j=3;j*j<=i;j+=2)if(i%j==0)break;
      if(j*j>i)cou++;
    }
    cout <<cou<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
  int n;
  while(cin>>n) {
    if(n==1)
      cout<<0<<endl;
    else {
    int no=0;
    for(int i=2;i<=n;i++) {
      for(int j=2;j<i;j++) {
	if(i%j==0) {
	  no++;
	  j=n;
	}
      }
    }
    cout<<n-no-1<<endl; 
  }
  }
 return 0;
}

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

int main() {
	int N;
	while(cin >> N){
		int is_prime[N+1];
		is_prime[0]=0; is_prime[1]=0;
		for(int i=2;i<N+1; i++){
			is_prime[i]=1;
		}
		
		for(int s=2; s<N+1; s++){
		
		if(is_prime[s]==1){	
		for(int i=s*s; i<N+1; i+=s){
			is_prime[i]=0;
		}}
		
		}
		int ans=0;
		for(int i=2; i<N+1; i++){
			ans+=is_prime[i];
		}
		cout << ans <<endl;
		
	}
	return 0;
}