Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		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:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

C++: #include <stdio.h>

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<=MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

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

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

#define ll long long
#define INF INT_MAX/3
#define pi 2*acos(0.0)
#define eps 1e-14

const int MAX_N = 1e+3;
const int MAX_M = 1e+2;
int n;
int a[MAX_N];
bool is_prime[1000000];
int prime[1000000];

int sieve(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() {
	while (cin >> n)
		cout << sieve(n) << endl;
	return 0;
}

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

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i])  {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }
  prime.erase(remove(prime.begin(), prime.end(), 0), prime.end());
  return prime;
}

int main() {
  int n;
  vector<int> prime;
  prime = sieve(1000000);

  while(cin >> n) {
    int count=0;

    for(vector<int>::iterator it=prime.begin(); it!=prime.end(); it++) {
      if(*it>n) break;
      count++;
    }
    cout << count <<endl;
  }
  return 0; 
}

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

#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))
#define mnv(v) (*min_element(v.begin(), v.end()))
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef string S;
typedef int I;

int x = 1000001 ;
bool prime[1000001] ;

void sev(){
    
    for(int i = 2; i*i <= x; i++)
    {
        
        for(int j = i*2; j <= x; j+=i)
        {
            prime[j] = true ;
        }
        
    }
    
}

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

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

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

int main(){
	int N =1000000;
	int n;
	int *data;
	data = new int[N];

	for(int i=0; i<N; i++){
		data[i] = -2;
	}
	data[0]=0; data[1]=0;


	for(int i=2;i<N;i++){
		if(prime(i)==true){
			data[i] = data[i-1]+1;
		}else{
			data[i]=data[i-1];
		}

//		if(i%(N/100)==0) cout << ".";

	}

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

	return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    ll n;
    while(cin>>n){
        vector<bool> ip;
        if(ip.size()<n+1){
            ip.resize(n+1,true);
        }
        ip[0]=false;
        ip[1]=false;
        for(int i=2;i<n+1;i++){
            for(int j=2;i*j<n+1;j++){
                ip[i*j]=false;
            }
        }
        ll ans=0;
        for(int i=0;i<n+1;i++){
            if(ip[i])ans++;
        }
        
        
        cout<<ans<<endl;
        
        
        
    }





return 0;
}

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

static const long MAX = 1000000L;
 
int main() {
    vector<long> prime;
    vector<long> dp;
    bool isPrime;
    long n, m;
 
    long i, len = sqrt(MAX) + 1;
    long j, lenJ;
    long k;
     
    prime.push_back(2);
    dp.push_back(0);
	dp.push_back(0);
	dp.push_back(1);

    for (i = 3; i <= len; i += 2) {
        isPrime = true;
        lenJ = prime.size();
        k = sqrt(i) + 1;
        for (j = 0; j < lenJ; j++) {
            if (k <= prime[j]) break;

            if (i % prime[j] == 0) {
                isPrime = false;

                break;
            }
	}

        if (isPrime) prime.push_back(i);
    }

    lenJ = prime.size();
     
    while (cin >> n) {
	if (n < dp.size()) {
		cout << dp[n] << endl;

		continue;
	}
         
	m = dp.size();
        for (i = m; i <= n; i += 2) {
            isPrime = true;

            k = sqrt(i) + 1;
            for (j = 0; j < lenJ; j++) {
                if (k <= prime[j]) break;

                if (i % prime[j] == 0) {
                    isPrime = false;

                    break;
                }
            }

            if (isPrime) {
		dp.push_back(dp.back() + 1);
		dp.push_back(dp.back());
	    } else {
		dp.push_back(dp.back());
		dp.push_back(dp.back());
	    }
        }
         
        cout << dp[n] << endl;
    }
 
    return 0;
}

C++: #include<iostream>
#include<math.h>
#include<fstream>
using namespace std;
int Test(int n);
int  main()
{
	fstream f;
	int n;
	f.open("taptin.txt", ios::in);
	f>>n;
	f.close();
	f.open("Ketqua.txt",ios::out);
	int t=0;
	if( n == 2)
	{
		t=1;
	}
	else
	{
		t =1;
		for(int i = 3 ; i <= n ; i= i+2)
		{
			if(i % 6 !=0)
			{
				if(Test(i)==1)
				{
					t= t+1;
				}
			}
		}
	}
	f<<t;
	f.close();
	return 0;
}
int Test(int n)
{
	for(int i = 2 ; i <= sqrt((float)n) ; i++)
	{
		if( n % i == 0)
			return 0;
	}
	return 1;
}

C++: #include <stdio.h>

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

C++: #include<stdio.h>
int num[999999];
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=999999;i++)
	num[i]=1;
for(int i=2;i<=999999;i+=2){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}