submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s647066454 | p00009 | Accepted | import math
def lb(a,x):
l=0
r=len(a)-1
while l<r:
mid=int((l+r)/2)
#print "l=",l,' r=',r
if a[mid]<x:
l=mid+1
else:
r=mid
return l
#maxn=1000001 // Wrong Answer?
maxn=1000010
a=[False for i in xrange(maxn)]
for i in xrange(2,int(math.sqrt(maxn))):
for j in xrange(i+i,maxn,i):
a[j]=True
b=[]
for i in xrange(2,maxn):
if not a[i]:
b.append(i)
while True:
try:
n=input()
f=lb(b,n)
if b[f]==n:
print(f+1)
else:
print(f)
except EOFError: break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s363483737 | p00009 | Accepted |
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def sieve(n):
p = [True for i in range(n + 1)]
p[0] = p[1] = False
end = int(n ** .5)
for i in range(2, end + 1):
if p[i]:
for j in range(i * i, n + 1, i):
p[j] = False
return p
def primes_below(n):
if n < 2: return 0
c = 1
for i in range(3, n + 1, 2):
if p[i]: c += 1
return c
p = sieve(1000000)
while 1:
try:
n = int(input())
except EOFError:
break
else:
print(primes_below(n)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s789259323 | p00009 | Accepted | def Eratosthenes(n):
N = [1 for i in range(0,n+1)]
i = 3
while i*i<=n:
if N[i]:
j = i*i
while j<=n:
N[j] = 0
j += i*2
i += 2
return N
N = Eratosthenes(999999)
while True:
try:
n = int(input())
except EOFError:
break
cnt = 0
if n>=2:
cnt = 1
for i in range(3, n+1, 2):
cnt += N[i]
print(cnt) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s882694265 | p00009 | Accepted | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def calc_prime(n):
p_list = [True]*n
p_list[0] = p_list[1] = False
for i in xrange(2,int(n**0.5)+1):
if p_list[i]:
for j in xrange(i*i,n,i):
p_list[j] = False
return [ i for i in xrange(2,n) if p_list[i] ]
prime_list = calc_prime(999999)
for s in sys.stdin:
d = int(s)
print len([prime_list[i] for i in range(len(prime_list)) if prime_list[i] <= d ]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s279012625 | p00009 | Accepted | import sys
n_list = map(int, sys.stdin.readlines())
n_max = max(n_list)
pn_candidates = [0] + [1] * (n_max - 1)
pn = 2
while pn <= n_max:
if pn_candidates[pn - 1] != 1:
pn += 1
continue
i = 2
while pn * i <= n_max:
pn_candidates[pn * i - 1] = 0
i += 1
pn += 1
for n in n_list:
print sum(pn_candidates[:n]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s978269324 | p00009 | Accepted | n = []
while True:
try:
n.append(int(raw_input()))
except:
break
R = max(n)+1
p = [1]*R
p[0] = p[1] = 0
i = 2
while i*i <= R:
if p[i]:
p[2*i::i] = [0 for x in range(2*i,R,i)]
i += p[i+1:].index(1)+1
for i in n:
print sum(p[:i+1]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s678216335 | p00009 | Accepted | n = []
while True:
try:n.append(int(raw_input()))
except:break
R = max(n)+1
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
if p[i]:
p[2*i::i] = [0]*len(p[2*i::i])
for i in n:
print sum(p[:i+1]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s577234371 | p00009 | Accepted | n = []
while True:
try:n.append(int(raw_input()))
except:break
R = max(n)+1
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
if p[i]:
p[2*i::i] = [0 for j in range(2*i,R,i)]
for i in n:
print sum(p[:i+1]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s308063482 | p00009 | Accepted | R = 1000000
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
if p[i]:
p[2*i::i] = [0]*len(p[2*i::i])
while True:
try:print sum(p[:int(raw_input())+1])
except:break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s216960631 | p00009 | Accepted | from bisect import bisect
R = 1000000
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0]*len(p[4::2])
for i in xrange(3,int(R**0.5)+1,2):
if p[i]:
p[i*i::i] = [0]*len(p[i*i::i])
prime = [i for i in xrange(2,R) if p[i]]
while True:
try:print bisect(prime,input())
except:break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s985304052 | p00009 | Accepted | # -*- coding;utf-8 -*-
def sieve(n):
p = 0
primes = []
is_prime = [True]*(n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n+1):
if(is_prime[i]):
primes.append(i)
p += 1
for j in range(i*2,n+1,i):#iごとに増える
is_prime[j] = False
return p
if(__name__ == "__main__"):
while(True):
try:
n = int(input())
except:
break
print(sieve(n))
| 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s817956612 | p00009 | Accepted | while True:
try:
n=int(input())
a=[True]*(n+1)
a[0]=a[1]=False
for i in range(2,int(n**0.5)+1):
if a[i]:
for j in range(i**2,n+1,i):
a[j]=False
print(a.count(True))
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s808152794 | p00009 | Accepted | lis=[1 for i in range(int(1e6+1))]
lis[0]=lis[1]=0
for i in range(int(1e6)+1):
if lis[i]:
for j in range(i*2,int(1e6+1),i):
lis[j]=0
while True:
try:
n=int(input())
cnt=0
for i in range(n+1):
if lis[i]:
cnt+=1
print(cnt)
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s089648361 | p00009 | Accepted | lis=[True for i in range(int(1e6+1))]
lis[0]=lis[1]=False
end=int(1e6**0.5)
for i in range(end+1):
if lis[i]:
for j in range(i*2,int(1e6+1),i):
lis[j]=False
while True:
try:
n=int(input())
cnt=0
for i in range(n+1):
if lis[i]:cnt+=1
print(cnt)
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s596587406 | p00009 | Accepted | def sieve(n):
p=[True for i in range(n+1)]
p[0]=p[1]=False
end=int(n**0.5)
for i in range(2,end+1):
if p[i]:
for j in range(i*i,n+1,i):
p[j]=False
return p
def solve(n):
if n<2:return 0
cnt=1
for i in range(3,n+1,2):
if p[i]:cnt+=1
return cnt
p=sieve(int(1e6))
while True:
try:
n=int(input())
print(solve(n))
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s658630769 | p00009 | Accepted | MAX = 1000000
prime = [1] * MAX
prime[0], prime[1] = 0, 0
i = 2
while i * i < MAX:
j = 2
while i * j < MAX:
prime[i * j] = 0
j += 1
i += 1
for k in range(1, len(prime)):
prime[k] += prime[k-1]
while True:
try:
n = int(raw_input())
print prime[n]
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s815836006 | p00009 | Accepted | # -*- coding: utf-8 -*-
import sys
def prime_list(n):
l = range(2,n+1)
i = 2
while i * i <= n:
l = filter(lambda x: x == i or x % i != 0, l)
i = i + 1
return l
def mark(s, x):
for i in xrange(x + x, len(s), x):
s[i] = False
def sieve(n):
s = [True] * n
for x in xrange(2, int(n**0.5) + 1):
if s[x]: mark(s, x)
return [i for i in xrange(0,n) if s[i] and i > 1]
if __name__ == '__main__':
l = sieve(999999)
for line in sys.stdin:
n = int(line)
print len([x for x in l if x <= n]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s480366195 | p00009 | Accepted | import sys
n = [int(line) for line in sys.stdin]
prime = [0, 0] + [1] * (max(n) - 1)
for i in range(len(prime)):
if prime[i]:
for j in range(2 * i, len(prime), i):
prime[j] = 0
for i in range(1, len(prime)):
prime[i] += prime[i - 1]
for ni in n:
print(prime[ni]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s722335444 | p00009 | Accepted | import itertools
import sys
N = 999999
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
primeb = [0 for i in range(N+1)]
for i in primes:
primeb[i] = 1
def isprime(n):
for p in primes:
if (n % p == 0):
return True
if (n < p*p):
return False
S = primes[-1]
for i in range(S, N):
if isprime(i):
pass
else:
primes.append(i)
primeb[i] = 1
for line in sys.stdin:
n = int(line)
print sum(primeb[:n+1]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s477806249 | p00009 | Accepted | def pri(s,n):
tab=[i for i in range(n+1) if s[i] and i>=2]
return(tab)
s=[True for _ in range(999999+1)]
i=2
while i**2<=999999:
if s[i]:
j=i*2
while j<=999999:
s[j]=False
j+=i
i+=1
while True:
try:
print(len(pri(s,int(input()))))
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s643021170 | p00009 | Accepted | import sys
n=999999
prime = [1]*(n+1)
(prime[0],prime[1])=(0,0)
for i in [v for v in xrange(2,n+1) if v*v<n+1]:
for j in xrange(i*i,n+1,i):
prime[j]=0
for inp in sys.stdin:
print prime[:int(inp)+1].count(1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s534088038 | p00009 | Accepted | def prime_table(n):
list = [True for _ in xrange(n + 1)]
i = 2
while i * i <= n:
if list[i]:
j = i + i
while j <= n:
list[j] = False
j += i
i += 1
table = [i for i in xrange(n + 1) if list[i] and i >= 2]
return table
table = prime_table(999999)
while True:
try:
n = int(raw_input())
except EOFError:
break
m = 0
for i in table:
if i<=n:
m+=1
else:
break
print m | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s115976529 | p00009 | Accepted | N = 1000000
p = [ 1 ] * N
( p[ 0 ], p[ 1 ] ) = ( 0, 0 )
for i in range ( len ( p ) ):
if ( p[ i ] ):
for j in range ( i * 2, len ( p ), i ):
p[ j ] = 0
for i in range ( 1, len ( p ) ):
p[ i ] += p[ i - 1 ]
while True:
try: n = int ( input ( ) )
except EOFError: break
print ( p[ n ] ) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s142782204 | p00009 | Accepted | #coding: UTF-8
# 指定した数以下の素数の個数を返却する
# 素数判定はエラストテネスのふるい
# 要素1000000のリスト(素数かどうかのリスト)を準備
max_number = 1000000
prime_flag_list = [True] * max_number
# 0、1は素数でない
prime_flag_list[0] = False
prime_flag_list[1] = False
# 2の倍数(2を除く)は素数でない
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
# 3以上の数について、素数ならその倍数を振るい落とす
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
# フラグの立ったままの箇所は素数なので、そこだけ取り出す
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
for i in range(0, len(prime_list)):
if prime_list[i] > input:
print i
break
if i >= len(prime_list) - 1:
print len(prime_list) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s137097931 | p00009 | Accepted | #coding: UTF-8
import bisect
# 指定した数以下の素数の個数を返却する
# 素数判定はエラストテネスのふるい
# 要素1000000のリスト(素数かどうかのリスト)を準備
max_number = 1000000
prime_flag_list = [True] * max_number
# 0、1は素数でない
prime_flag_list[0] = False
prime_flag_list[1] = False
# 2の倍数(2を除く)は素数でない
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
# 3以上の数について、素数ならその倍数を振るい落とす
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
# フラグの立ったままの箇所は素数なので、そこだけ取り出す
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect.bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s454979674 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
# 指定した数以下の素数の個数を返却する
# 素数判定はエラストテネスのふるい
# 要素1000000のリスト(素数かどうかのリスト)を準備
max_number = 1000000
prime_flag_list = [True] * max_number
# 0、1は素数でない
prime_flag_list[0] = False
prime_flag_list[1] = False
# 2の倍数(2を除く)は素数でない
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
# 3以上の数について、素数ならその倍数を振るい落とす
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
# フラグの立ったままの箇所は素数なので、そこだけ取り出す
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
# 素数リスト(ソート済み)の中に、入力した数値を入れるとしたら何項目目になるかを
# bisectで求める
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s818775552 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
max_number = 1000000
prime_flag_list = [True] * max_number
prime_flag_list[0] = False
prime_flag_list[1] = False
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s127608383 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
max = 1000000
pflist = [True] * max
pflist[0] = False
pflist[1] = False
pflist[4::2] = [False] * len(pflist[4::2])
for i in range(3, int(max**0.5) + 1, 2):
pflist[i*i::i] = [False] * len(pflist[i*i::i])
prime_list = [i for i in range(2, max) if pflist[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s127450474 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
max_number = 1000000
prime_flag_list = [1] * max_number
prime_flag_list[0] = 0
prime_flag_list[1] = 0
prime_flag_list[4::2] = [0] * len(prime_flag_list[4::2])
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [0] * len(prime_flag_list[i*i::i])
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s380950233 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
max_number = 1000000
prime_flag_list = [True] * max_number
prime_flag_list[0] = False
prime_flag_list[1] = False
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s065052510 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
max_number = 1000000
prime_flag_list = [True] * max_number
prime_flag_list[0] = prime_flag_list[1] = False
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
for i in range(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s276124209 | p00009 | Accepted | #coding: UTF-8
from bisect import bisect_right
max_number = 1000000
prime_flag_list = [True] * max_number
prime_flag_list[0] = False
prime_flag_list[1] = False
prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])
for i in xrange(3, int(max_number**0.5) + 1, 2):
prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])
prime_list = [i for i in xrange(2, max_number) if prime_flag_list[i]]
while True:
try:
input = int(raw_input())
except EOFError:
break
print bisect_right(prime_list, input) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s096770088 | p00009 | Accepted | max_num = 1000000
cnt = 0
p = [1] * max_num
p[0] = p[1] = 0
for i in xrange(2, int(max_num ** 0.5) + 1):
if p[i]:
p[i * i::i] = [0] * len(p[i * i::i])
for i in xrange(max_num):
cnt += p[i]
p[i] = cnt
while True:
try: print(p[int(raw_input())])
except: break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s868009470 | p00009 | Accepted | import sys
p=[1]*999999
p[0]=p[1]=0
p[4::2]=[0]*len(p[4::2])
for i in xrange(3,1000,2):p[i*i::i]=[0]*len(p[i*i::i])
for n in sys.stdin:print p[0:int(n)+1].count(1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s676260678 | p00009 | Accepted | def prime_count(n):
j = 0
ans = [1] * (n + 1)
ans[0] = ans[1] = 0
for i in xrange(3, n + 1, 2):
if i * 2 > n:
break
if ans[i] != 0:
for j in xrange(2 * i, n + 1, i):
ans[j] = 0
for k in xrange(2 * 2, n + 1, 2):
ans[k] = 0
print sum(ans)
try:
while True:
n = input()
prime_count(n)
except EOFError:
pass | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s746974681 | p00009 | Accepted | # coding: utf-8
#Problem Name: Prime Number
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp
__max = 999999
List = [False,True]*(__max/2+1)
List[1] = False
List[2] = True
for i in xrange(3,int(__max**.5)+1,2):
List[i**2::i] = [False]*len(List[i**2::i])
List = [i for i in xrange(2,__max) if List[i]]
while True:
try:
n = int(raw_input())
print __import__('bisect',fromlist=['bisect_right']).bisect_right(List,n)
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s990827278 | p00009 | Accepted | import math
import sys
def pi(n):
m = int(math.sqrt(n))
keys = [n / i for i in range(1, m + 1)]
keys += range(keys[-1] - 1, 0, -1)
h = {i : i - 1 for i in keys}
for i in range(2, m + 1):
if h[i] > h[i - 1]:
hp = h[i - 1]
i2 = i * i
for j in keys:
if j < i2: break
h[j] -= h[j / i] - hp
return h[n]
for line in sys.stdin:
i = int(line)
print pi(i) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s841363462 | p00009 | Accepted | import sys
l = [True] * 1000000
for i in range(2, 1000000):
if (l[i - 1]):
for j in range(i ** 2 - 1, 1000000, i):
l[j] = False
for s in sys.stdin:
print(l[1:int(s)].count(True)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s060754900 | p00009 | Accepted | prime = [True]*1111111;
prime[0] = False
prime[1] = False
i = 0
while i < 1111111:
if prime[i]:
j = 2*i
while j < 1111111:
prime[j] = False
j += i
i += 1
while True:
try:
n = int(raw_input())
ans = 0
for i in range(n+1):
if(prime[i]):
ans += 1
print ans
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s097759901 | p00009 | Accepted | LIMIT = 10000000
isPrime = [True for _ in range(LIMIT)]
isPrime[0] = isPrime[1] = False
for i in range(2, int(LIMIT ** 0.5)+1):
if isPrime[i]:
for j in range(i * i, LIMIT, i):
isPrime[j] = False
try:
while True:
n = int(input())
count = 0
if n >= 2:
count = 1
for i in range(3, n+1, 2):
if isPrime[i]:
count += 1
print(count)
except EOFError:
pass | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s769384097 | p00009 | Accepted | import sys
def primeTable(n):
list = [True for _ in range(n+1)]
i = 2
while i * i <= n:
if list[i]:
j = i+i
while j<= n:
list[j] = False
j += i
i += 1
table = [i for i in range(n+1) if list[i] and i >= 2]
return table
lines = sys.stdin.readlines()
primeList = primeTable(999999)
for line in lines:
inp = int(line)
primes = list(filter(lambda n:n>=2 and n<=inp, primeList))
num = len(primes)
print (num) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s075572919 | p00009 | Accepted | import sys
MAX_N = 1000000
prime = []
is_prime = [True for i in xrange(MAX_N)]
for i in xrange(2, MAX_N):
if is_prime[i] == True:
prime.append(i)
for j in xrange(i, MAX_N, i):
is_prime[j] = False
LEN = len(prime)
for line in sys.stdin:
n = int(line)
cnt = 0
for i in xrange(LEN):
if prime[i] <= n:
cnt += 1
else:
break
print cnt | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s520040848 | p00009 | Accepted | import sys
input_list = list(int(i) for i in sys.stdin)
max_n = min(1000000, max(input_list) + 1)
prime_list = list(i % 2 for i in range(max_n))
prime_list[1], prime_list[2] = 0, 1
i = 3
while i * i < max_n:
if prime_list[i]:
for j in range(i * 2, max_n, i):
prime_list[j] = 0
i += 2
for i in range(1, max_n):
prime_list[i] += prime_list[i - 1]
inset = sorted((n, i) for i, n in enumerate(input_list))
outset = sorted((t[1], prime_list[t[0]]) for t in inset)
for t in outset:
print(t[1]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s746520668 | p00009 | Accepted | from bisect import bisect
def sieve(n):
prime = [True] * n
prime[0] = prime[1] = False
for i in xrange(2, int(n ** 0.5) + 1):
if prime[i]:
for j in range(i ** 2, n, i):
prime[j] = False
return [i for i in xrange(2, n) if prime[i]]
primes = sieve(999999)
while True:
try:
print bisect(primes, input())
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s945417923 | p00009 | Accepted | #! -*- coding:utf-8 -*-
import sys
# import time
for line in sys.stdin:
n=int(line)
# n=input()
# start = time.time()
#plist = [1 for i in xrange(n+1)]
#??¨??¨1???????????????
#1?????¨???????????????????´???°??¨??????
plist = [1]*(n+1)
#0??¨1????´???°?????????????????§0???????????????
plist[0]=plist[1]=0
i=2
#??¶??°????????????????????????
while True:
pos0 = 2*i
if pos0 < len(plist):
plist[pos0] = 0
else:
break
i+=1
#???????????¨????????????????????????
for x in xrange(3,int(n**0.5)+1):
if plist[x]:
for pos0 in xrange(x**2,n+1,x):
plist[pos0] = 0
# elapsed_time = time.time()-start
# print elapsed_time
print plist.count(1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s537712983 | p00009 | Accepted | import sys
ary=[]
for i in sys.stdin:
ary.append(int(i))
m = max(ary)
prime=[1] * (m + 1)
prime[0] = prime[1] = 0
for i in range(2, int(m ** 0.5) + 1):
if prime[i] == 1:
for j in range(i*2, m + 1, i):
prime[j] = 0
for i in range(len(ary)):
print(sum(prime[:ary[i] + 1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s863181145 | p00009 | Accepted | from bisect import bisect
def sieve(n):
num = [True]*n
num[0] = num[1] = False
for i in xrange(2,int(n**0.5)+1):
if num[i]:
for j in xrange(i**2, n, i):
num[j] = False
return [i for i in xrange(2,n) if num[i]]
prime = sieve(999999)
while True:
try:
print bisect(prime, input())
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s675936846 | p00009 | Accepted | def mk_table(n):
res = [1] * (n + 1)
res[:2] = [0, 0]
for i in range(2, n):
if i ** 2 > n:
break
if res[i] == 1:
j = 2
while i * j <= n:
res[i * j] = 0
j += 1
return res
tbl = mk_table(999999)
try:
while 1:
print(len([x for x in tbl[:int(input())+1] if x == 1]))
except Exception:
pass | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s838174276 | p00009 | Accepted | def mk_table(n):
res = [1] * (n + 1)
res[:2] = 0, 0
for i in range(2, n):
if i ** 2 > n:
break
if res[i] == 1:
for j in range(i*2, n + 1, i):
res[j] = 0
return res
tbl = mk_table(999999)
try:
while 1:
print(len([x for x in tbl[:int(input())+1] if x == 1]))
except Exception:
pass | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s051994445 | p00009 | Accepted | def sieve(n):
p = [True for i in range(n + 1)]
p[0] = p[1] = False
end = int(n ** .5)
for i in range(2, end + 1):
if p[i]:
for j in range(i * i, n + 1, i):
p[j] = False
return p
def primes_below(n):
if n < 2: return 0
c = 1
for i in range(3, n + 1, 2):
if p[i]: c += 1
return c
p = sieve(1000000)
while 1:
try:
n = int(input())
except EOFError:
break
else:
print(primes_below(n)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s151437789 | p00009 | Accepted | def sieve(n):
p=[True for i in range(n+1)]
p[0]=p[1]=False
for i in range(2,n+1):
if p[i]==True:
for j in range(i*i,n+1,i):
p[j]=False
return p
def solve(n):
if n<2:return 0
c=1
for i in range(3,n+1,2):
if p[i]==1:
c+=1
return c
p=sieve(1000000)
while True:
try:
n = int(input())
print(solve(n))
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s812264493 | p00009 | Accepted | import sys
n=10**6
p=[1]*n
p[0],p[1]=0,0
for i in xrange(2,int(n**0.5)+1):
if p[i]==1:
for j in xrange(i**2,n,i):
p[j]=0
for i in xrange(2,n):
p[i]+=p[i-1]
for line in sys.stdin.readlines():
print p[int(line)] | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s206896442 | p00009 | Accepted | #!/usr/bin/env python3
import itertools
import math
import sys
MAX = 999999
def sieve_of_eratosthenes(max):
is_prime = [True] * (max + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(math.sqrt(max)) + 1):
if not is_prime[i]:
continue
for j in range(i * i, max + 1, i):
is_prime[j] = False
return filter(lambda x: is_prime[x], range(max + 1))
def main():
p = list(sieve_of_eratosthenes(MAX))
for l in sys.stdin:
n = int(l)
print(len(list(itertools.takewhile(lambda x: x <= n, p))))
if __name__ == '__main__':
main() | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s057621081 | p00009 | Accepted | def main():
while True:
try:
n = int(input())
a = [True] * (n+1)
a[0] = a[1] = False
for i in range(2, int(n**0.5)+1):
if a[i]:
for j in range(i**2, n+1, i):
a[j] = False
print(a.count(True))
except:
break
if __name__ == '__main__':
main() | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s955508300 | p00009 | Accepted | # -*- coding: utf-8 -*-
import sys
import math
def countPrimes(n):
m = int(math.sqrt(n))
keys = [n/i for i in range(1, m+1)]
keys += range(keys[-1]-1, 0, -1)
h = {i:i-1 for i in keys}
for i in range(2, m+1):
if h[i] > h[i-1]:
hp = h[i-1]
i2 = i*i
for j in keys:
if j < i2:
break
h[j] -= h[j/i]-hp
return h[n]
for line in sys.stdin:
print countPrimes(int(line)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s041345328 | p00009 | Accepted | import sys
MAX = 1000000
A = tuple(range(2, MAX))
B = tuple()
while True:
if (A[0])**2 > MAX:
break
B = B + (A[0],)
A = tuple(x for x in A if x % A[0] != 0)
B = B + A
Lines = sys.stdin.readlines()
for line in Lines:
print(len([x for x in B if x <= int(line)])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s271518584 | p00009 | Accepted | def sieve(n):
p=0
prime=[0]*n
is_prime=[0]*(n+1)
for i in xrange(n+1):
is_prime[i]=True
is_prime[0]=is_prime[1]=False
for i in xrange(2,n+1):
if is_prime[i]:
p+=1
prime[p]=i
for j in xrange(2*i,n+1,i):
is_prime[j]=False
return p
while 1:
try:
n=input()
print(sieve(n))
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s440211611 | p00009 | Accepted | import sys
import math
M = 1000000
B = int(math.sqrt(M)+1)
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = [1] * N1
m = [1] * N2
for i in range(5,B,6):
p = (i-5)//6
ini = (i*5-1)//6
if l[p] == 1:
l[p+i::i] = [0] * len(l[p+i::i])
m[ini-1::i] = [0] * len(m[ini-1::i])
if m[p] == 1:
m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
for i in sys.stdin:
n = int(i)
r = n-1 if n < 4 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
print(r) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s559977892 | p00009 | Accepted | import sys
import math
M = 1000000
B = int(math.sqrt(M)+1)
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = [1] * N1
m = [1] * N2
for i in range(5,B,6):
p = (i-5)//6
k = p+i
ini = (i*5-1)//6
if l[p] == 1:
l[k::i] = [0] * len(l[k::i])
m[ini-1::i] = [0] * len(m[ini-1::i])
if m[p] == 1:
m[k+2::i+2] = [0] * len(m[k+2::i+2])
l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
for i in sys.stdin:
n = int(i)
r = n-1 if n < 4 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
print(r) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s150888607 | p00009 | Accepted | import sys
import math
import bisect
M = 1000000
B = int(math.sqrt(M)+1)
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = [1] * N1
m = [1] * N2
o = []
for i in range(5,B,6):
p = (i-5)//6
ini = (i*5-1)//6
if l[p] == 1:
l[p+i::i] = [0] * len(l[p+i::i])
m[ini-1::i] = [0] * len(m[ini-1::i])
if m[p] == 1:
m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
for i in range(N1):
if l[i] == 1:
o.append(6*i+5)
if m[i] == 1:
o.append(6*i+7)
if N2>N1 and m[N1] ==1:
o.append(6*N1+7)
for i in sys.stdin:
n = int(i)
r = n-1 if n < 4 else bisect.bisect_right(o, n)+2
print(r) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s418797352 | p00009 | Accepted | import sys
import math
M = 1000000
B = int(math.sqrt(M)+1)
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = [1] * N1
m = [1] * N2
for i in range(5,B,6):
p = (i-5)//6
ini = (i*5-1)//6
if l[p] == 1:
l[p+i::i] = [0] * len(l[p+i::i])
m[ini-1::i] = [0] * len(m[ini-1::i])
if m[p] == 1:
m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
for i in sys.stdin:
n = int(i)
r = n-1 if n < 3 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
print(r) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s664917238 | p00009 | Accepted | import sys
import math
M = 1000000
B = int(math.sqrt(M)+1)//6+1
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = [1] * N1
m = [1] * N2
i = 5
ini = 4
for p in range(B):
if l[p] == 1:
l[p+i::i] = [0] * len(l[p+i::i])
m[ini-1::i] = [0] * len(m[ini-1::i])
if m[p] == 1:
m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
i += 6
ini += 5
for i in sys.stdin:
n = int(i)
r = n-1 if n < 3 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
print(r) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s762691571 | p00009 | Accepted | from math import sqrt
I_list=[]
prime_list=[]
while True:
try:
I_list.append(int(input()))
except:
break
I_max=max(I_list)
search_set={x for x in range(2,I_max+1)}
p=-1
while p<=sqrt(I_max):
p=min(search_set)
prime_list.append(p)
search_set={x for x in search_set if x%p !=0 }
search_list=sorted(list(search_set))
prime_list+=search_list
#print(prime_list)
for i in I_list:
lower_set={j for j in prime_list if j<=i }
# print(lower_set)
print(len(lower_set)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s923367253 | p00009 | Accepted | era = [True]*1000001
for i in range(2, 1000001):
if era[i-2]:
for j in range(i*2, 1000001, i):
era[j-2] = False
while True:
try:
n = int(raw_input())
print era[:n-1].count(True)
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s078799286 | p00009 | Accepted | import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
n = int(i)
if prime[len(prime)-1] < n:
for i in range(prime[len(prime)-1]+1,n+1):
if isPrime[i] == 1:
prime.append(i)
for j in range(i*2, 1000000, i):
isPrime[j] = 0
print(sum(isPrime[:n+1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s427481011 | p00009 | Accepted | # sieve of Eratosthenes
N = 1000000
isprimer = [True for i in range(N)]
isprimer[0], isprimer[1] = False, False
for i in range(2, N):
if not isprimer[i]:
continue
for j in range(i * 2, N, i):
isprimer[j] = False
while True:
try:
num = eval(input())
count = 0
for i in range(2, num + 1):
if isprimer[i]:
count += 1
print(count)
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s520712575 | p00009 | Accepted | while True:
try:
n = int(input())
nums = list(range(n + 1))
nums[1] = 0
for i in range(n):
if nums[i] > n ** 0.5:
break
if nums[i] == 0:
continue
for j in range(nums[i] * 2, n + 1, nums[i]):
nums[j] = 0
print(n + 1 - nums.count(0))
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s655406047 | p00009 | Accepted | prime = [1 for i in range(1000000)]
prime[0] = 0
prime[1] = 0
for i in range(1000):
if prime[i] == 1:
for j in range(2, 1000000):
try:
prime[i * j] = 0
except:
break
for i in range(1, 1000000):
prime[i] = prime[i] + prime[i - 1]
while True:
try:
n = int(input())
print(prime[n])
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s836024247 | p00009 | Accepted | # ?´???°?????°?????¨?????????????????°??????
import sys
import math
prim_no = {2: True} # ????????°????´???°??§??????????????????????????????
def is_prime(no):
if no == 2 or no == 1:
return True
if no % 2 == 0:
return False
if prim_no.get(no) is not None:
return prim_no.get(no)
max_check = int(math.sqrt(no))
for i in range(3, max_check+1, 2):
if no % i == 0:
prim_no[no] = False
return False
prim_no[no] = True
return True
def main():
prim_vals = {} # ????????°?????§????´???°????????°
while True:
num = sys.stdin.readline()
if num is None or num.strip() == '':
break
num = int(num.strip())
if prim_vals.get(num) is not None:
cnt = prim_vals.get(num)
else:
#print('num:', num)
if num == 1:
cnt = 0
else:
cnt = 0
#for i in range(3, num + 1, 2):
if num % 2 == 0:
start_num = num -1
else:
start_num = num
for i in range(start_num, 0, -2):
#print('i:', i)
if prim_vals.get(i) is not None:
cnt += prim_vals.get(i)
#cnt -= 1
break
if is_prime(i):
cnt += 1
#cnt += 1 # 2??????????¶????
prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????(2?????????)
print(cnt)
if __name__ == '__main__':
main()
#print(prim_no) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s691367788 | p00009 | Accepted | # ?´???°?????°?????¨?????????????????°??????
import sys
import math
prim_no = {2: True} # ????????°????´???°??§??????????????????????????????
def is_prime(no):
if no == 2 or no == 1:
return True
if no % 2 == 0:
return False
if prim_no.get(no) is not None:
return prim_no.get(no)
max_check = int(math.sqrt(no))
for i in range(3, max_check+1, 2):
if no % i == 0:
prim_no[no] = False
return False
prim_no[no] = True
return True
def main():
prim_vals = {} # ????????°?????§????´???°????????°
while True:
num = sys.stdin.readline()
if num is None or num.strip() == '':
break
num = int(num.strip())
if prim_vals.get(num) is not None:
cnt = prim_vals.get(num)
else:
if num == 1:
cnt = 0
else:
cnt = 0
if num % 2 == 0:
start_num = num -1
else:
start_num = num
for i in range(start_num, 0, -2):
if prim_vals.get(i) is not None:
cnt += prim_vals.get(i)
break
if is_prime(i):
cnt += 1
prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????
print(cnt)
if __name__ == '__main__':
main()
#print(prim_no) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s625626749 | p00009 | Accepted | # ?´???°?????°?????¨?????????????????°??????
import sys
import math
prim_no = {2: True} # ????????°????´???°??§??????????????????????????????
def is_prime(no):
if no == 2 or no == 1:
return True
if no % 2 == 0:
return False
if prim_no.get(no) is not None:
return prim_no.get(no)
max_check = int(math.sqrt(no))
for i in range(3, max_check+1, 2):
if no % i == 0:
prim_no[no] = False
return False
prim_no[no] = True
return True
def main():
prim_vals = {} # ????????°?????§????´???°????????°
num_data = [] # ?????????????????????
while True:
num = sys.stdin.readline()
if num is None or num.strip() == '':
break
num = int(num.strip())
num_data.append(num)
sorted_num_data = sorted(num_data)
prim_num = {}
for num in sorted_num_data:
if prim_vals.get(num) is not None:
cnt = prim_vals.get(num)
else:
if num == 1:
cnt = 0
else:
cnt = 0
if num % 2 == 0:
start_num = num -1
else:
start_num = num
for i in range(start_num, 0, -2):
if prim_vals.get(i) is not None:
cnt += prim_vals.get(i)
break
if is_prime(i):
cnt += 1
prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????
prim_num[num] = cnt
for num in num_data:
print(prim_num[num])
if __name__ == '__main__':
main()
#print(prim_no) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s000329514 | p00009 | Accepted | import math
import sys
lst=[0 for _ in xrange(999999+1)]
def is_prime(num):
if num%2==0:
return 0
for x in range(3, int(num**0.5)+1,2):
if num % x==0:
return 0
return 1
lst[1]=0
lst[2]=1
for idx in range(3, len(lst)):
lst[idx] = is_prime(idx) + lst[idx-1]
for line in sys.stdin:
print lst[int(line)] | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s776192759 | p00009 | Accepted | import sys
def primes(n):
ps = []
table = [True] * n
table[0] = False
for i in range(n):
if table[i]:
for j in range(2 * (i + 1) - 1, n, i + 1):
table[j] = False
for i in range(n):
if table[i]:
ps.append(i + 1)
return ps
for line in sys.stdin:
n = int(line)
print(len(primes(n))) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s360266880 | p00009 | Accepted | # -*- coding: utf-8 -*-
import sys
def eratosthenes_sieve(n):
table = [0]*(n + 1)
prime_list = []
for i in range(2, n + 1):
if table[i] == 0:
prime_list.append(i)
for j in range(i + i, n + 1, i):
table[j] = 1
return prime_list
def prime(n):
return eratosthenes_sieve(n)
def main():
inp = [int(n) for n in sys.stdin]
for n in inp:
n_pn = len(prime(n))
print(n_pn)
if __name__ == '__main__':
main() | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s656107196 | p00009 | Accepted |
import math
m=999999
s=int(math.sqrt(m)+1)
li=[0]*m
li[0]=1
for i in range(1,s):
if li[i]==0:
li[i*2+1::i+1]=[1 for e in range(len(li[i*2+1::i+1]))]
while True:
try:n=int(input())
except:break
print(len([i for i in li[:n:] if i==0]))
| 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s095033822 | p00009 | Accepted | import sys
for line in sys.stdin:
n = int(line)
flag = [True]*(n+1)
flag[0] = flag[1] = False
for i in range(2,int(n**0.5)+1):
if flag[i]:
for j in range(i**2, n+1, i):
flag[j] = False
print(flag.count(True)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s074343578 | p00009 | Accepted | def erato(n):
s = list(range(n+1))
s[1] = 0
for e in s:
if e:
for i in range(e*2, n+1, e):
s[i] = 0
return s
e = erato(1000000)
while True:
try:
n = int(input())
print(len(list(filter(lambda x:x, e[:n+1]))))
except:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s593570838 | p00009 | Accepted | p = [True for _ in xrange(1000000)]
p[0] = False
p[1] = False
for i in xrange(1000000):
if p[i]:
for j in xrange(i+i, 1000000, i):
p[j] = False
ans = [0 for _ in xrange(1000000)]
for i in xrange(2, 1000000):
ans[i] = ans[i-1] + p[i]
import sys
for line in sys.stdin:
N = int(line)
print ans[N] | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s717195486 | p00009 | Accepted | def sieve_prime(n): # return prime numbers within [1, n]
primes = []
is_prime = [True] * (n+1) # [0, n]
for i in range(2, n+1):
if not is_prime[i]:
continue # need only primes
primes.append(i)
for j in range(i*2, n+1, i): # range(i*2, n+1, i) = {i*2, i*3, ...}
is_prime[j] = False
"""
Compare the above code with the below one in the view of time complexity
for j in range(i*2, n+1):
if j % i == 0:
is_prime[j] = False
"""
return primes
while True:
try:
n = int(input())
print(len(sieve_prime(n))) # because T <= 30, you can simply use sieve_prime every time
except EOFError:
break | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s743545383 | p00009 | Accepted | import math
import sys
a = [1]*10000000
a[0] = a[1] = 0
for i in range(2,int(math.sqrt(2000000))):
if a[i] == 1:
for j in range(i+i,2000000,i):
a[j] = 0
for i in range(1,2000000):
a[i] += a[i-1]
for line in sys.stdin:
print(a[int(line)])
| 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s135518998 | p00009 | Accepted | import sys
def create_prime_list(limit):
""" ??¨??????????????????????????§limit?????§????´???°?????????????±???????
https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
"""
x = limit**0.5
primes = []
nums = tuple(x for x in range(2, limit+1))
while nums[0] <= x:
primes.append(nums[0])
current_prime = nums[0]
nums = tuple(x for x in nums if x % current_prime != 0)
primes.extend(nums)
return primes
if __name__ == '__main__':
# ?´???°?????§?????¨???
primes = create_prime_list(999999)
# ??????????????\???
for line in sys.stdin:
target = int(line)
ans = tuple(x for x in primes if x <= target)
print(len(ans)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s733806972 | p00009 | Accepted | # -*- coding: utf-8 -*-
import sys
array=[]
for i in sys.stdin:
array.append(int(i))
m=max(array)
prime=[1]*(m+1)
prime[0]=prime[1]=0
for i in range(2,int(m**0.5)+1):
if prime[i] ==1:
for j in range(i*i,m+1,i):
prime[j]=0
for i in range(len(array)):
print(sum(prime[:array[i]+1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s074143176 | p00009 | Accepted | # coding: utf-8
# Here your code !
import sys
import math
def primes(x):
if x < 2: return []
primes = [i for i in range(x)]
primes[1] = 0 # 1????´???°??§?????????
# ??¨??????????????????????????????
for prime in primes:
if prime > math.sqrt(x): break
if prime == 0: continue
for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0
return [prime for prime in primes if prime != 0]
prime_list = primes(1000000)
for line in sys.stdin:
n = int(line)
count = 0
for p in prime_list:
if p > n:
break
count += 1
print(count) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s025906539 | p00009 | Accepted | import sys
prime=[False]*1000000
for i in range(2,1001):
for j in range(i*2,1000000,i):
prime[j]=True
for n in sys.stdin:
cnt=0
for i in range(2,int(n)+1):
if not prime[i]:
cnt+=1
print(cnt) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s865844259 | p00009 | Accepted |
prime=[False]*1000000
for i in range(2,1001):
for j in range(i*2,1000000,i):
prime[j]=True
while True:
try:
n=int(input())
except:
break
print(prime[2:n+1].count(False)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s753935851 | p00009 | Accepted | prime=[True]*1000000
np=[0]*1000000
for i in range(2,1000000):
if prime[i]:
for j in range(i*2,1000000,i):
prime[j]=False
np[i]=np[i-1]+prime[i]
while True:
try:
n=int(input())
except:
break
print(np[n]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s941163823 | p00009 | Accepted | prime=[True]*1000000
np=[0]*1000000
for i in range(2,1000):
if prime[i]:
for j in range(i*2,1000000,i):
prime[j]=False
while True:
try:
n=int(input())
except:
break
print(sum(prime[2:n+1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s401736916 | p00009 | Accepted | prime=[True]*1000000
for i in range(2,1000):
if prime[i]:
for j in range(i*2,1000000,i):
prime[j]=False
while True:
try:
n=int(input())
except:
break
print(sum(prime[2:n+1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s872535088 | p00009 | Accepted | from math import sqrt
I_list=[]
prime_list=[]
while True:
try:
I_list.append(int(input()))
except:
break
I_max=max(I_list)
search_set={x for x in range(2,I_max+1)}
p=-1
while p<=sqrt(I_max):
p=min(search_set)
prime_list.append(p)
search_set={x for x in search_set if x%p !=0 }
search_list=sorted(list(search_set))
prime_list+=search_list
#print(prime_list)
for i in I_list:
lower_set={j for j in prime_list if j<=i }
# print(lower_set)
print(len(lower_set)) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s918546600 | p00009 | Accepted | import sys
import math
N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])
for i in range(3,int(math.sqrt(N)),2):
if primes[i]:
primes[i*i::i*2] = [0] * len(primes[i*i::i*2])
for i in sys.stdin:
n = int(i)
print(sum(primes[0:n+1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s978480803 | p00009 | Accepted | import sys
import math
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
for i in range(3,int(math.sqrt(N)),2):
if primes[i//2]:
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
for i in sys.stdin:
n = int(i)
if n == 1:
print(0)
elif n == 2:
print(1)
else:
print(sum(primes[0:(n+1)//2])+1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s358829137 | p00009 | Accepted | import sys
import math
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
for i in (x for x in range(3,int(math.sqrt(N)),2) if primes[x//2]):
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
for i in sys.stdin:
n = int(i)
if n == 1:
print(0)
elif n == 2:
print(1)
else:
print(sum(primes[0:(n+1)//2])+1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s417552597 | p00009 | Accepted | import sys
import math
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
for i in range(3,int(math.sqrt(N)),2):
if primes[i//2]:
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
for i in sys.stdin:
n = int(i)
if n < 3:
print(n-1)
else:
print(sum(primes[0:(n+1)//2])+1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s441382967 | p00009 | Accepted | import sys
import math
N = 1000000
primes = [1] * (N//2+1)
primes[0] = 1
for i in range(3,int(math.sqrt(N))+1,2):
if primes[i//2]:
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
primes[i//2] += primes[i//2-1]
for i in range(int(math.sqrt(N))+1,N+1,2):
primes[i//2] += primes[i//2-1]
for i in sys.stdin:
n = int(i)
if n == 1:
print(0)
elif n == 2:
print(1)
else:
print(primes[(n-1)//2]) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s663263161 | p00009 | Accepted | import sys
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
for i in range(3,int(N**0.5),2):
if primes[i//2]:
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
for i in sys.stdin:
n = int(i)
if n < 3:
print(n-1)
else:
print(sum(primes[:(n+1)//2])+1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s977707188 | p00009 | Accepted | import sys
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
for i in range(3,int(N**0.5),2):
if primes[i//2]:
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
for i in sys.stdin:
n = int(i)
if n < 4:
print(n-1)
else:
print(sum(primes[:(n+1)//2])+1) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s534812942 | p00009 | Accepted | import sys
xx = 500000
f = [0, 1] * xx
i = 3
while i * i <= 2 * xx:
if f[i] == 1:
j = i * i
while j <= 2 * xx:
f[j] = 0
j += i + i
i += 2
f.pop(0)
f.pop(1)
for n in sys.stdin:
i = int(n)
if i < 2:
print(0)
else:
print(sum(f[:i - 1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s427696003 | p00009 | Accepted | import sys
xx = 500000
f = [0, 1] * xx
i = 3
while i * i <= 2 * xx:
if f[i] == 1:
j = i * i
while j <= 2 * xx:
f[j] = 0
j += i + i
i += 2
f.pop(0)
f.pop(1)
for n in sys.stdin:
i = int(n)
if i < 2:
print(0)
else:
print(sum(f[:i - 1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s170124844 | p00009 | Accepted | import sys
f = [0, 1] * 500000
i = 3
while i <= 1000:
if f[i] == 1:
j = i * i
while j <= 1000000:
f[j] = 0
j += i + i
i += 2
f.pop(0)
f.pop(1)
for n in sys.stdin:
i = int(n)
if i < 2:
print(0)
else:
print(sum(f[:i - 1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
s396266475 | p00009 | Accepted | import sys
f = [0, 1] * 500000
f.append(0)
f[1] = 0
f[2] = 1
i = 3
while i < 1000:
if f[i] == 1:
j = i * i
while j <= 1000000:
f[j] = 0
j += i + i
i += 2
for n in sys.stdin:
i = int(n)
print(sum(f[:i + 1])) | 10
3
11
| 4
2
5
|
<H1>Prime Number</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset has an integer <var>n</var> (1 ≤ <var>n</var> ≤ 999,999) in a line.
</p>
<p>
The number of datasets is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each dataset, prints the number of prime numbers.
</p>
<H2>Sample Input</H2>
<pre>
10
3
11
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.