Problem:
Chebyshev's Theorem
If
n
is a positive integer,
there exists at least one prime number greater than
n
and less than or equal to 2
n
.
This fact is known as Chebyshev's theorem or the Bertrand-Chebyshev theorem,
which had been conjectured by Joseph Louis François Bertrand (1822–1900)
and was proven by Pafnuty Lvovich Chebyshev (Пафнутий Львович Чебышёв, 1821–1894) in 1850.
Srinivasa Aiyangar Ramanujan (1887–1920) gave an elementary proof in his paper published in 1919.
Paul Erdős (1913–1996) discovered another elementary proof in 1932.
For example, there exist 4 prime numbers greater than 10 and less than or equal to 20, i.e. 11, 13, 17 and 19.
There exist 3 prime numbers greater than 14 and less than or equal to 28, i.e. 17, 19 and 23.
Your mission is to write a program that counts the prime numbers greater than
n
and less than or equal to 2
n
for each given positive integer
n
.
Using such a program, you can verify Chebyshev's theorem for individual positive integers.
Input
The input is a sequence of datasets.
A dataset is a line containing a single positive integer
n
.
You may assume
n
≤ 123456.
The end of the input is indicated by a line containing a single zero.
It is not a dataset.
Output
The output should be composed of as many lines as the input datasets.
Each line should contain a single integer and should never contain extra characters.
The output integer corresponding to a dataset consisting of an integer
n
should be the number of the prime numbers
p
satisfying
n
<
p
≤ 2
n
.
Sample Input
1
10
13
100
1000
10000
100000
0
Output for the Sample Input
1
4
3
21
135
1033
8392

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

template <typename A> void chmin(A &l, const A &r) {
    if(r < l)
        l = r;
}
template <typename A> void chmax(A &l, const A &r) {
    if(l < r)
        l = r;
}

ll mod = 998244353;

ll n;
vector<char> is_prime(400000, 1);
void input() {
    cin >> n;
    is_prime[0] = 0;
    is_prime[1] = 0;
    for(int i = 2; i < is_prime.size(); i++) {
        if(is_prime[i]) {
            for(int j = 2 * i; j < is_prime.size(); j += i) {
                is_prime[j] = 0;
            }
        }
    }
}

void solve() {
    ll ans = 0;
    for(int i=n+1;i<=2*n;i++)
    {
        ans += is_prime[i];
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(1) {
        input();
        if(n == 0)
            break;
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 300
memory_kb: 3436
final_rank: 8

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

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<long long, long long>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using vvvi = vector<vector<vector<int>>>;
using pii = pair<int, int>;
using vvb = vector<vector<bool>>;
using Graph = vector<vector<ll>>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 998244353;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (m); i >= (int)(n); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

vi dx4 = {1, 0, -1, 0}, dy4 = {0, 1, 0, -1};
vi dx8 = {1, 1, 1, 0, 0, -1, -1, -1}, dy8 = {1, 0, -1, 1, -1, 1, 0, -1};

int main()
{
    vi cnt(250000, 0);
    rep3(i, 2, 250001)
    {
        bool ok = true;
        rep3(j, 2, sqrt(i) + 1)
        {
            if (i % j == 0)
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            cnt[i]++;
        }
    }
    rep(i, 250000) { cnt[i + 1] += cnt[i]; }
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            break;
        }
        cout << cnt[2 * n] - cnt[n] << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3768
final_rank: 7

code_snippet: // AOJ 1172 - Chebyshev's Theorem
// ICPC Japan Domestic Contest 2011 - Problem A

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

bool solving() {
  int N; cin >> N;
  if(N == 0) return false;

  unordered_set<int> prime;
  for(int i=2; i<=2*N; ++i) prime.insert(i);
  int rt = sqrt(2*N);
  while((rt+1)*(rt+1) <= 2*N) ++rt;
  while((rt-1)*(rt-1) >= 2*N) --rt;
  for(int i=2; i<=rt; ++i) {
    for(int j=i; i*j<=2*N; ++j) {
      prime.erase(i*j);
    }
  }
  for(int i=2; i<=N; ++i) prime.erase(i);
  cout << prime.size() << endl;
  return true;
}

int main() {
  while(solving()) {}
}
accuracy: 1
time_ms: 1130
memory_kb: 15056
final_rank: 20

code_snippet: #if __has_include(<yoniha/all.h>)
#include <yoniha/all.h>
using namespace atcoder;
#else
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#endif
using namespace std;

#define int long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n - 1); i >= 0; i--)
template <typename T> bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template <typename T> bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

// using mint = modint;

void solve(int n){
  vector isprime(2 * n + 1, true);
  for(int p = 2; p <= 2 * n; p++){
    if(!isprime.at(p)) continue;
    for(int i = 2; p * i <= 2 * n; i++) isprime.at(p * i) = false;
  }
  cout << reduce(isprime.begin() + n + 1, isprime.end(), 0ll) << '\n';
}

signed main(){
  while(true){
    int n; cin >> n;
    if(n == 0) break;
    solve(n);
  }
}
accuracy: 1
time_ms: 40
memory_kb: 3584
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <functional>
using namespace std;
using ll = long long;
using lb = long double;

int is_prime(int n);

vector<int> prime(2*123456+1, -1);  //-1: unknown, 0: not prime, 1: prime
int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) return 0;
        int ans = 0;
        int double_n = 2*n;
        n++;
        while (n <= double_n) {
            if (is_prime(n) == 1) ans++;
            n++;
        }
        cout << ans << endl;
    }
    return 0;
}

int is_prime(int n) {
    if (prime[n] != -1) return prime[n];
    else {
        bool primeflag = true;
        for (int i = 2; i < sqrt(n)+1; i++) {
            if (n != i && n%i == 0) {primeflag = false; break;}
        }
        if (primeflag) {
            prime[n] = 1;
            for (int i = 0; i < prime.size(); i++) {
                if (prime[i] == 1) {
                    for (int j = 2; i*j < n; j++) {
                        prime[i*j] = 0;
                    }
                }
            }
        }
        else prime[n] = 0;
        return prime[n];
    }
}
accuracy: 1
time_ms: 4930
memory_kb: 3960
final_rank: 19

code_snippet: // 123456
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string> //to_string等
#include <functional>
using namespace std;
using ll = long long;
using lb = long double;

int main(){

        vector<int>pn(0);

        auto isPrime = [&](int num){
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        };

        for(int i=0;i<=123456*2;i++){
            if(isPrime(i)){
                pn.push_back(i);
            }
        }

        while(true){
            int n;
            cin >> n;
            if(n==0)return 0;
            int cnt=0;
            for(int i=0;i<pn.size();i++){
                if(pn[i] > n && pn[i]<= n*2){
                    cnt++;
                }
            }
            cout << cnt << endl;
        }

}
accuracy: 1
time_ms: 10
memory_kb: 3492
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
using PP = pair<int, P>;
using PLL = pair<ll, ll>;
using PPLL = pair<ll, PLL>;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rrep(i, n) for(ll i = n - 1; i >= 0; --i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
#define all(v) v.begin(), v.end()
#define nC2(n) n * (n - 1) / 2
constexpr ll INF = 9009009009009009009LL;
constexpr int INF32 = 2002002002;
constexpr ll MOD = 998244353;
constexpr ll MOD107 = 1000000007;

// Linear Algebra ////////////////////////////////////////////////
const double Rad2Deg = 180.0 / M_PI;
const double Deg2Rad = M_PI / 180.0;
//////////////////////////////////////////////////////////////////

int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

template <class T>
inline bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename Container,
          typename = std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              std::is_convertible_v<decltype(std::declval<Container>().begin()),
                                    typename Container::iterator>>>
ostream &operator<<(ostream &os, const Container &container) {
    auto it = container.begin();
    auto end = container.end();

    if (it != end) {
        os << *it;
        ++it;
    }
	for (; it != end; ++it) {
		os << " " << *it;
	}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1) os << " ";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {
	for (size_t i = 0; i < vv.size(); ++i) {
		os << vv[i];
		if (i != vv.size() - 1) os << "\n";
    }
    return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	assert(v.size() > 0);
	for (size_t i = 0; i < v.size(); ++i) is >> v[i];
	return is;
}
template <typename T>
istream& operator>>(istream& is, vector<vector<T>>& vv) {
	assert(vv.size() > 0);
	for (size_t i = 0; i < vv.size(); ++i) is >> vv[i];
	return is;
}

struct phash {
	template<class T1, class T2>
    inline size_t operator()(const pair<T1, T2> & p) const {
        auto h1 = hash<T1>()(p.first);
        auto h2 = hash<T2>()(p.second);

		size_t seed = h1 + h2; 
		h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = (h1 >> 16) ^ h1;
        seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
		h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = (h2 >> 16) ^ h2;
        seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};




/**
 * @brief エラトステネスの篩 O(N log log N)
 * @param n 素数を求める範囲
 * @return vector<bool> xが素数かどうか
 */
vector<bool> sieve(const ll n) {
	vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i * i <= n; ++i) {
		if (!is_prime[i]) continue;
		for (ll j = i * i; j <= n; j += i) is_prime[j] = false;
	}
	return is_prime;
}

/**
 * @brief エラトステネスの篩 O(N log log N)
 * @param n 素数を求める範囲
 * @return vector<ll> 素数のリスト
 */
vector<ll> primes(const ll n) {
	vector<bool> is_prime(n + 1, true);
	vector<ll> res;
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i <= n; ++i) {
		if (!is_prime[i]) continue;
		res.push_back(i);
		for (ll j = i * i; j <= n; j += i) is_prime[j] = false;
	}
	return res;
}

int solve() {
	ll n; cin >> n;
	if (n == 0) return 1;

	const ll MAX = 123456 * 2;
	unordered_set<ll> p;
	for (auto x : primes(MAX)) {
		p.insert(x);
	}

	ll ans = 0;
	loop(i, n + 1, 2 * n) {
		if (p.count(i)) ans++;
	}

	cout << ans << endl;

	return 0;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	while (!solve()) { }

	return 0;
}
accuracy: 1
time_ms: 660
memory_kb: 4404
final_rank: 14

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
bool is_p(ll n)
{
    if (n == 1)
    {
        return false;
    }
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<ll> cnt(1);
    rep(i, 1, 300000)
    {
        cnt.push_back(cnt[i - 1] + is_p(i));
    }
    while (true)
    {
        ll n;
        cin >> n;
        if (n == 0)
        {
            break;
        }
        cout << cnt[2 * n] - cnt[n] << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 8548
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name
#define REP1(n) for(ll i=0;i<n;i++)
#define REP2(i, n) for (ll i=0;i<n;i++)
#define REP3(i, a, n) for (ll i=a;i<n;i++)
#define REP4(i, a, b, n) for(ll i=a;i<n;i+=b)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name
#define RREP1(n) for(ll i=n;i>=0;i--)
#define RREP2(i, n) for(ll i=n;i>=0;i--)
#define RREP3(i, a, n) for(ll i=n;i>=a;i--)
#define RREP4(i, a, b, n) for(ll i=n;i>=a;i-=b)
#define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define foa(a,v)  (auto& a : (v))
#define uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define len(n) (long long)(n).size()
#define pb push_back
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvvc = vector<vvc>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
template<class... T>
constexpr auto min(T... a){
    return min(initializer_list<common_type_t<T...>>{a...});
}
template<class... T>
constexpr auto max(T... a){
    return max(initializer_list<common_type_t<T...>>{a...});
}
template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}
ll modpow(ll a,ll b,ll c){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b /= 2;
    }
    return ans;
}
#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; input(__VA_ARGS__)
#define CHA(...) char __VA_ARGS__; input(__VA_ARGS__)
#define VLL(name,length) vll name(length);rep(i,length){cin >> name[i];}
#define VVLL(name,h,w) vvll name(h,vll(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLL(name,a,b,c) vvvll name(a,vvll(b,vll(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VI(name,length) vi name(length);rep(i,length){cin >> name[i];}
#define VVI(name,h,w) vvi name(h,vi(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVI(name,a,b,c) vvvi name(a,vvll(b,vi(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VLD(name,length) vld name(length);rep(i,length){cin >> name[i];}
#define VVLD(name,h,w) vvld name(h,vld(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLD(name,a,b,c) vvvld name(a,vvld(b,vld(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VC(name,length) vc name(length);rep(i,length){cin >> name[i];}
#define VVC(name,h,w) vvc name(h,vc(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVC(name,a,b,c) vvvc name(a,vvc(b,vc(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VS(name,length) vs name(length);rep(i,length){cin >> name[i];}
#define VVS(name,h,w) vvs name(h,vs(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVS(name,a,b,c) vvvs name(a,vvs(b,vs(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define PLL(name) pll name;cin>>name.first>>name.second;
#define VPLL(name,length) vpll name(length);rep(i,length){cin>>name[i].first>>name[i].second;}

void print(){cout << "\n";}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}
void print(vll x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void print(vvll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}



int main(){
    while(1){
        LL(n);
        if(n == 0){break;}

        auto check = [&](int x){
            rep(i,2,x){
                if(x % i == 0){
                    return 0;
                }
                if(i * i > x + 1000){break;}
            }
            return 1;
        };
        auto solve = [&](){
            ll ans = 0;
            rep(i,n+1,2*n+1){
                if(check(i)){
                    ans++;
                }
            }
            print(ans);
        };
        solve();
    }
}
accuracy: 1
time_ms: 370
memory_kb: 3584
final_rank: 11

code_snippet: #include <iostream>
#include <cmath>
using namespace std;

bool is_prime[246913];
int n,count;

bool isPrime(int n){
    if(n%6!=1&&n%6!=5){
        return false;
    }

    for(int i=5;i<=(int)(sqrt(n));i+=6){
        if(n%i==0||n%(i+2)==0){
            return false;
        }
    }
    return true;

}

void findPrime(){
    is_prime[2]=true;
    is_prime[3]=true;
    for(int i=5;i<=246912;i++){
        if(isPrime(i)){
            is_prime[i]=true;
        }
    }
    
}

int main(){
    findPrime();
    while(cin>>n,n!=0){
        for(int i=n+1;i<=2*n;i++){
            if(is_prime[i]){
                count++;
            }
        }
        cout<<count<<endl;
        count=0;
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3328
final_rank: 2

code_snippet: #include <iostream>
using namespace std;

// 簡略化された素数判定関数
bool isPrime(int num) {
    if (num == 2) return true; // 2は素数
    if (num % 2 == 0) return false; // 偶数は素数ではない
    for (int i = 3; i * i <= num; i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    while (1) {
        cin >> n;
        if (n == 0) break;

        int primeCount = 0;

        // nより大きく2n以下の素数の数を数える
        for (int i = n + 1; i <= 2 * n; ++i) {
            if (isPrime(i)) {
                ++primeCount;
            }
        }

        cout << primeCount << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 2996
final_rank: 3

code_snippet: #include <iostream>
using namespace std;

// 素数判定関数
bool isPrime(int num) {
    if (num <= 1) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;
    for (int i = 3; i * i <= num; i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    while (1) {
        cin >> n;
        if (n == 0) break;

        int primeCount = 0;

        // nより大きく2n以下の素数の数を数える
        for (int i = n + 1; i <= 2 * n; ++i) {
            if (isPrime(i)) {
                ++primeCount;
            }
        }

        cout << primeCount << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 3088
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

vector<bool> hurui(int max_num)
{
    vector<bool> isPrime(max_num + 1, true);
    isPrime[0] = isPrime[1] = false;

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

    return isPrime;
}
int main()
{
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            break;
        }

        int ttimesn = 2 * n, count = 0;
        vector<bool> is_prime = hurui(ttimesn);  
        for (int i = n + 1; i <= ttimesn; i++) {
            if (is_prime[i]) {
                count++;
            }
        }

        cout << count << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3104
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
using ll=long long;

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

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0) break;
        int cnt=0;

        for(int i=n+1;i<=2*n;i++){
            if(isprime(i)) cnt++;
        }

        cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 300
memory_kb: 3436
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

bool IsPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    while(true) {
        ll n, n1, n2, ans = 0;
        cin >> n;
        if(n == 0) {
            break;
        }
        n1 = n + 1;
        n2 = 2 * n;
        for(ll i = n1; i <= n2; i++) {
            if(IsPrime(i)) {
                ans++;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 3388
final_rank: 12

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

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<long long, long long>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using vvvi = vector<vector<vector<int>>>;
using pii = pair<int, int>;
using vvb = vector<vector<bool>>;
using Graph = vector<vector<ll>>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 998422353;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (m); i >= (int)(n); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

vi dx4 = {1, 0, -1, 0}, dy4 = {0, 1, 0, -1};
vi dx8 = {1, 1, 1, 0, 0, -1, -1, -1}, dy8 = {1, 0, -1, 1, -1, 1, 0, -1};

bool isprime(long long n)
{
    if (n <= 1)
        return false;
    for (long long p = 2; p * p <= n; p++)
    {
        if (n % p == 0)
            return false;
    }
    return true;
}

int main()
{
    while (1)
    {
        // 宣言・入力の受け取り
        int n;
        cin >> n;
        // 終了条件
        if (n == 0)
        {
            break;
        }
        // 宣言・入力の受け取り

        // solve
        int ans = 0;
        rep3(i, n + 1, 2 * n + 1)
        {
            if (isprime(i))
            {
                ans++;
            }
        }
        // 出力
        cout << ans << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 980
memory_kb: 3372
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
bool isPrime(int x){
    if(x==1)return false;
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}
int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        int cnt=0;
        for(int i=n+1;i<=2*n;i++){
            if(isPrime(i))cnt++;
        }
        cout << cnt << endl;
    }
}
accuracy: 1
time_ms: 300
memory_kb: 3440
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    vector<int> res;

    while(true) {
        int n; cin >> n;
        if(n==0) break;
        int ans = 0;

        for(int i = n+1; i <= 2*n; i++) {
            bool ok = true;
            for(int j = 2; j * j <= i; j++) {
                if(i%j==0) {
                    ok = false;
                }
            }
            if(ok == true) ans++;
            
        }
        res.push_back(ans);
    }

    for(int i = 0; i < res.size(); i++) cout << res[i] << endl;

    return 0;       
}
accuracy: 1
time_ms: 3310
memory_kb: 3140
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;

int n;

void solve() {
    int ans = 0;
    reps(i,n+1,2*n+1) {
        if (i == 2) {
            ans++;
            continue;
        }
        if (i%2 == 0) {
            continue;
        }
        bool q = true;
        for (int j = 3; j < min((int)pow(i,0.5)+10,i-1); j+=2) {
            if (i%j == 0) {
                q = false;
                break;
            }
        }
        if (q) {
            ans++;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    while (true) {
        cin >> n;
        if (n == 0) {
            return 0;
        }
        solve();
    }
}
accuracy: 1
time_ms: 3120
memory_kb: 3740
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> prime;
  for(int i = 2; i < 10000000; i++){
    int is_prime = 1;
    for(int j = 0; j < (int)prime.size() && prime[j] * prime[j] <= i; j++){
      if(i % prime[j] == 0){
        is_prime = 0;
        break;
      }
    }
    if(is_prime)prime.push_back(i);
  }
  // for(int i = 0; i < 25; i++)cout << prime[i] << endl;
  while(1){
    int n;
    cin >> n;
    if(n == 0)break;
    cout << distance(upper_bound(prime.begin(),prime.end(),n),upper_bound(prime.begin(),prime.end(),2 * n)) << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 540
memory_kb: 8036
final_rank: 16