Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int whether(int num);
int count(int num);

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

int whether(int num){
    int s=sqrt(num);
    int i;
    
    for(i=3; i<=s; i+=2){
        if(num%i==0){ return 0; }
    }
    
    return 1;
}

int count(int num){
    int a=1;
    if(num<2){ return 0; }
    if(num==2){ return 1; }
    for(int i=3; i<=num; i+=2){
        if(whether(i)){ a+=1; }
    }
    
    return a;
}

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

int main()
{
	int n;
	int max;
	while(cin>>n)
	{
		max = sqrt(1.0*n);
		vector<bool> prime(n+1, true);
		prime[0]=false;
		prime[1]=false;
		for(int i=2; i<=max; ++i)
		{
			if(prime[i])
			{
				for(int j=i*2; j<=prime.size()-1; j+=i)
				{
					prime[j]=false;
				}
			}
		}
		cout << accumulate(prime.begin(), prime.end(), 0) << '\n';
	}
}

C++: #ifndef VS
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<math.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {
	cww() { CIN_ONLY{ ios::sync_with_stdio(false); cin.tie(0); } }
}star;
#define DEBUG if(0)
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r) { bool a = l>r; if (a)l = r; return a; }
template <typename T>inline bool chmax(T &l, T r) { bool a = l<r; if (a)l = r; return a; }
namespace prime {
	const int size = 1123456;
	int p[size];
	struct prime {
		prime(){
			REP(i, size)p[i] = 1;
			p[0] = p[1] = 0;
			REP(i, size)if (p[i]) {
				for (int j = i + i; j < size; j += i)p[j] = 0;
			}
			FOR(i, 1, size) {
				p[i] += p[i - 1];
			}
		}
	}prime_init;
}
int main() {
	int n;
	while (cin >> n) {
		cout << prime::p[n] << endl;
	}
}

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

long long gcd(long long a, long long b)
{
    return b?gcd(b,a%b):a;
}
long long m,n;
int main()
{
    while(~scanf("%lld%lld",&m,&n))
    {
        long long temp = gcd(m,n);
        printf("%lld %lld\n",temp,m/temp*n);
    }
    return 0;
}

C++: #include <iostream>
int main(int argc, const char * argv[])
{

    // insert code here...
    
    while(true)
    {
        int n;
        std::cin >> n;
        int count = 0;
        
        for(int i=2;i<n;i++)
        {
            bool flag = true;
            for(int j=2;j<i/j+1;j++)
            {
                if(i%j==0)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                count++;
            }
        }
        
        std::cout << count <<"\n";
        
    }
    
    return 0;
}

C++: #include <iostream>

using namespace std;

void solve(int n) {
	int prime[n];
	int j=0;
	for (int i=2; i<=n; i++) {
		prime[j] = i;
		j++;
	}
	int p;
	for (int i=0; i<n; i++) {
		p = prime[i];
		if (p == -1) continue;
		for (int k=i+1; k<n; k++) {
			if (prime[k]%p == 0)
				prime[k] = -1;
		}
	}
	int count = 0;
	for (int i=0; i<n; i++)
		if (prime[i] != -1) count++;
	cout << count << endl;
}

int main() {
	int n;
	while (cin >> n) {
		if (n<=1) cout << 0 << endl;
		solve(n);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		sosu[i]=(flag)? cnt++ : cnt;		
	}
	//for(int i=0;i<30;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

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

int gcd(int a, int b)
{
    if(b==0)
        return a;

    return gcd(b, a%b);
}

int main(){
    bool is_prime[1000000];

    is_prime[0] = is_prime[1] = false;

    for(int i=2; i<1000000; i++){
        is_prime[i] = true;
    }

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

    int n_prime[1000000];

    int cnt = 0;
    for(int i=0; i<1000000; i++){
        if(is_prime[i]){
            cnt++;
        }
        n_prime[i] = cnt;
    }

    while(1){
        int n;
        cin >> n;
        if(cin.eof()){
            break;
        }
        cout << n_prime[n] << endl;
    }
}

C++: ///BISMILLAHIR RAHMANIR RAHMIM
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000002
int pri[MAX+2];
int cnt[MAX+2];
void sieve(int n)
{
    pri[1]=1;
    for (int i=2;i<=n;i++)
    {
        if(pri[i]==0)
        {
            for (int j=i+i;j<=n;j+=i)
            {
                pri[j]=1;
            }
        }
    }
    int tot = 0;
    for(int i = 1;i<=n;i++)
    {
        if(pri[i]==0)
            tot++;
        cnt[i] = tot;
    }
}
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    sieve(MAX);
    int n;
    while(cin>>n)
    {
        cout << cnt[n] << "\n";
    }
    return 0;
}

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

bool is_sosu(int x){
	int i;
	if(x<2) return false;
	for(i=2;i<=sqrt((double)x);i++){
		if(x%i==0) return false;
	}
	return true;
}

int main()
{
	long int n,x;
	int ans;
	while(cin>>n){
		ans=0;
		for(x=1;x<=n;x++){
			if(is_sosu(x)==true) ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define ll long long
#define mx 1000000+7
bool a[mx+10];
ll pr[mx], p;

using namespace std;
ll sieve(ll n);
int main()
{
    ll i, j,k, l, m, n;
   while(scanf("%lld", &n)==1)
   {
       m = sieve(n);
    printf("%lld\n", m);
   }

}
ll sieve(ll n)
{
    p = 0;
    ll i, j, k;
    k = sqrt(n);
    pr[p++] = 2;
    for(i = 4; i <= n; i+=2)
        a[i]=1;
    for(i = 3; i <= n; i+=2)
    {
        if(a[i] ==0)
            pr[p++]=i;
        if(i <= k)
            if(a[i] == 0)
        {
            for(j = i*i; j <= n; j+=2*i)
                a[j]=1;
        }
    }
    return p;
}

C++: #include <cstdio>
#include <memory.h>

int n;
int MAX_N=1000004;
bool DP[1000005] ;//素数リスト「素数じゃなかったらtrue」


int main()
{
	memset(DP,false,sizeof(DP));
	while(scanf("%d",&n)!=EOF)
	{
	 	int count=0;
		for(int i=1;i<n;i++)
		{
			DP[0]=true;
			DP[1]=true;
			if(DP[i]==false)
			{
				count++;
				for(int j=i*2;j<MAX_N;j+=i)DP[j]=true;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}