submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s936614994 | p00009 | Accepted | import sys
n=1000000
pr=[1]*n
pr[0],pr[1]=0,0
for i in xrange(2,int(n**0.5)+1):
if pr[i]==1:
for j in xrange(i**2,n,i):
pr[j]=0
for i in xrange(2,n):
pr[i]+=pr[i-1]
for line in sys.stdin:
print pr[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>
|
s436070248 | p00009 | Accepted |
import sys
def prime_list(n):
limit = int(n ** 0.5) + 1
lis = range(1, n + 1, 2)
lis[0] = 2
while True:
if len(lis) == 0:
break
p = lis.pop(0)
yield p
if p <= limit:
lis = [x for x in lis if x % p != 0]
def primes_number(n):
primes = []
for p in prime_list(n):
primes.append(p)
return primes
ns = map(int, sys.stdin.readlines())
max_n = max(ns)
primes = primes_number(max_n)
for n in ns:
p = len(filter(lambda x: x <= n, primes))
print p | 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>
|
s914965684 | p00009 | Accepted | max = 1000000
candidates = [True for x in range(0, max + 1)]
candidates[0] = False
candidates[1] = False
for i in range(2, max / 2):
if not candidates[i]:
continue
j = i + i
while True:
if max < j:
break
candidates[j] = False
j += i
while True:
try:
n = int(raw_input())
print len([i for i in candidates[0:n+1] if i])
except Exception:
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>
|
s180167819 | p00009 | Accepted | import math
max = 1000000
candidates = [True for x in xrange(0, max + 1)]
candidates[0] = False
candidates[1] = False
for i in xrange(2, int(math.sqrt(max))):
if not candidates[i]:
continue
j = i + i
while True:
if max < j:
break
candidates[j] = False
j += i
while True:
try:
n = int(raw_input())
print len([i for i in candidates[0:n+1] if i])
except Exception:
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>
|
s626843424 | p00009 | Accepted | p = [1]
n = [0,0]
c = 0
for i in range(1,1000000):
p.append(0)
for i in range(2,1000000):
if p[i]==1 :
n.append(c)
continue
c += 1
n.append(c)
for j in range(i*i,1000000,i):
if p[j]==0 : p[j]=1
while True:
try:
nn = int(raw_input())
print n[nn]
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>
|
s466157749 | p00009 | Accepted | import sys
def sieve(n):
prime = [True] * (n + 1)
prime[0] = prime[1] = False
for i in xrange(2, int((n + 1) ** 0.5) + 1):
if prime[i]:
for j in xrange(i * i, n + 1, i):
prime[j] = False
return [i for i in xrange(2, n + 1) if prime[i]]
for line in sys.stdin:
n = int(line)
print len(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>
|
s766481769 | p00009 | Accepted | import math
def get_primes(max_number):#return prime list smaller than max_number
if max_number == 2:
return [2]
elif max_number < 3:
return []
numbers=range(1, max_number + 2, 2)
nroot=math.floor(max_number ** 0.5)
n=len(numbers)
numbers[0]=0
for i in range(1, n):
x = numbers[i]
if x > nroot:
break
if x and i + x < n:
for j in range(i+x,n,x):
numbers[j] = 0
x=[2] + filter(None, numbers[1:])
return x
n=[]
i=0
while (True):
try:
n.append([i,input(), 0])
i+=1
except:
break
n=sorted(n, key=lambda x: x[1])
for i, e in enumerate(get_primes(n[-1][1])):
for j in range(len(n)):
if e<=n[j][1]:
n[j][2]+=1
n=sorted(n, key=lambda x: x[0])
for e in n:
print e[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>
|
s423912867 | p00009 | Accepted | m = 1000000
p = [True] * (m+1)
for i in range(2, m+1):
if p[i-2]:
for j in range(i*2, m+1, i):
p[j-2] = False
while True:
try:
n = int(raw_input())
print p[: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>
|
s600631633 | p00009 | Accepted | # Prime Number
import sys
MAX_NUM = 1000000
ROOT_MAX_NUM = 1000
primes = [1] * MAX_NUM
primes[0] = primes[1] = 0
for i in xrange(2, ROOT_MAX_NUM):
if not primes[i]:
continue
for j in xrange(i+i, MAX_NUM, i):
primes[j] = 0
datas = []
for line in sys.stdin:
datas.append(int(line))
for data in datas:
count = 0
for i in xrange(data+1):
if primes[i]:
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>
|
s208586246 | p00009 | Accepted | p = [0 for x in range(999999)]
for x in xrange(1,999999,2):
z = int(x**0.5)+1
for y in xrange(3,z,2):
if x % y == 0:
break
else:
p[x] = 1
p[1], p[2] = 0, 1
while 1:
try:
n = input()
print sum(p[:n+1])
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>
|
s088183486 | p00009 | Accepted | import math
import sys
n = 999999
nums = [1] * (n+1)
nums[:2] = [0,0]
cnt = 0
while cnt <= math.sqrt(n):
flg = nums[cnt]
if flg == 1:
k = 2
while k*cnt <= n:
nums[k*cnt] = 0
k += 1
cnt += 1
for line in sys.stdin:
n = int(line)
print sum(nums[: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>
|
s692993722 | p00009 | Accepted | import sys,random
rand = random.randint
def prime(n):
if n == 2:
return True
if n < 2 or n & 1 == 0:
return False
d = (n-1) >> 1
while d & 1 == 0:
d >>= 1
for i in range(10):
a = rand(1,n-1)
t = d
y = pow(a,t,n)
while t != n-1 and y != 1 and y != n-1:
y = pow(y,2,n)
t <<= 1
if y != n-1 and t & 1 == 0:
return False
return True
a = [prime(i) for i in range(1000000)]
for s in sys.stdin:
i = int(s)
print(a[:i+1].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>
|
s821914633 | p00009 | Accepted | import sys,random
rand = random.randint
def prime(n):
if n == 2:
return True
if n < 2 or n & 1 == 0:
return False
d = (n-1) >> 1
while d & 1 == 0:
d >>= 1
for i in range(5):
a = rand(1,n-1)
t = d
y = pow(a,t,n)
while t != n-1 and y != 1 and y != n-1:
y = pow(y,2,n)
t <<= 1
if y != n-1 and t & 1 == 0:
return False
return True
a = [prime(i) for i in range(1000000)]
for s in sys.stdin:
i = int(s)
print(a[:i+1].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>
|
s654850537 | p00009 | Accepted | import sys,random
rand = random.randint
def prime(n):
if n == 2:
return True
if n < 2 or n & 1 == 0:
return False
d = (n-1) >> 1
while d & 1 == 0:
d >>= 1
for i in range(4):
a = rand(1,n-1)
t = d
y = pow(a,t,n)
while t != n-1 and y != 1 and y != n-1:
y = pow(y,2,n)
t <<= 1
if y != n-1 and t & 1 == 0:
return False
return True
a = [prime(i) for i in range(1000000)]
for s in sys.stdin:
i = int(s)
print(a[:i+1].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>
|
s634743168 | p00009 | Accepted | import sys,random
rand = random.randint
def prime(n):
if n == 2:
return True
if n < 2 or n & 1 == 0:
return False
d = (n-1) >> 1
while d & 1 == 0:
d >>= 1
for i in range(3):
a = rand(1,n-1)
t = d
y = pow(a,t,n)
while t != n-1 and y != 1 and y != n-1:
y = pow(y,2,n)
t <<= 1
if y != n-1 and t & 1 == 0:
return False
return True
a = [prime(i) for i in range(1000000)]
for s in sys.stdin:
i = int(s)
print(a[:i+1].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>
|
s058215046 | p00009 | Accepted | import sys
a = [True] * 1000000
for i in range(2,1000000):
if(a[i-1]):
for j in range(i**2-1, 1000000, i):
a[j] = False
for s in sys.stdin:
print(a[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>
|
s906054817 | p00009 | Accepted | import sys,math
def prime(m):
N=range(1,m+2,2)
r=int(m**.5)
h=len(N)
N[0]=0
for i in range(h):
x=N[i]
if x>r:break
if x and i+x<h:N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
N[0]=2
return filter(None,N)
A=map(int,sys.stdin)
n=max(A)
B=[0]*(n+1)
i=0
c=0
for e in prime(n):
while e>i:
B[i]=c
i+=1
c+=1
if i==n+1:break
else:
for i in range(i,n+1):B[i]=c
for e in A:print B[e] | 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>
|
s105116704 | p00009 | Accepted | # -*- coding: utf-8 -*-
import sys
limit = 1000000
prime01List = [1]*limit
prime01List[0] = 0 # 1 is not prime
for i in xrange(2, int(limit**0.5)+1):
n = 2*i
while(n <= limit):
prime01List[n-1] = 0
n += i
ansList = [0]*limit
cnt = 0
for i in xrange(limit):
cnt += prime01List[i]
ansList[i] = cnt
#for line in ["999999"]:
for line in sys.stdin.readlines():
List = map(int, line.strip().split())
n = List[0]
print ansList[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>
|
s920217939 | p00009 | Accepted | import math
prime = [1 for i in range(999999)]
prime[0] = 0
for i in range(2,999999/2):
prime[2*i-1] = 0
for i in range(3,int(math.sqrt(999999)),2):
mx = 2*i
while mx <= 999999:
prime[mx-1] = 0
mx += i
while True:
try:
n = int(raw_input())
print sum(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>
|
s248358892 | p00009 | Accepted | import math
r = 999999
sqrt = int(math.sqrt(r))
prime = [1 for i in range(r)]
prime[0] = 0
for i in range(2,r/2):
prime[2*i-1] = 0
for i in range(3,sqrt,2):
mx = 2*i
while mx <= r:
prime[mx-1] = 0
mx += i
while True:
try:
n = int(raw_input())
print sum(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>
|
s254019173 | p00009 | Accepted | import math
r = 999999
sqrt = int(math.sqrt(r))
prime = [1 for i in range(r)]
prime[0] = 0
for i in range(2,r/2):
prime[2*i-1] = 0
for i in range(3,sqrt,2):
for j in range(2*i,r+1,i):
prime[j-1] = 0
while True:
try:
n = int(raw_input())
print sum(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>
|
s561518495 | p00009 | Accepted | import math
r = 999999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*(i+1)-1,r,i+1):
p[j] = 0
while True:
try:
n = int(raw_input())
print sum(p[: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>
|
s907568400 | p00009 | Accepted | import math
r = 999999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
while True:
try:
n = int(raw_input())
print sum(p[: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>
|
s079646791 | p00009 | Accepted | import math
r = 999999
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
while True:
try:
n = int(raw_input())
print p[:n].count(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>
|
s211453984 | p00009 | Accepted | import math
r = 999999
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
while True:
try:
n = int(raw_input())
print sum(p[: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>
|
s599155594 | p00009 | Accepted | import math
n = []
while True:
try:
n.append(int(raw_input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
for i in n:
print sum(p[: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>
|
s195763521 | p00009 | Accepted | import math
n = []
while True:
try:
n.append(int(raw_input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
for i in n:
print sum(p[: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>
|
s805200694 | p00009 | Accepted | import math
n = []
while True:
try:
n.append(int(raw_input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
p[3::2] = [0 for x in range(3,r,2)]
for i in range(2,sqrt,2):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
for i in n:
print sum(p[: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>
|
s643611279 | p00009 | Accepted | import sys
ifprime = [1]*(1000000)
ifprime[0] = ifprime[1] = 0
a = 2
while a < 1000000:
if ifprime[a]:
b = a*a
while b < 1000000:
ifprime[b] = 0
b += a
a += 1
for n in sys.stdin:
print sum(ifprime[:int(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>
|
s472444619 | p00009 | Accepted | #!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
def prime(n):
l=[True for _ in range(n+1)]
i=2
while i**2<=n:
if l[i]:
j=i+i
while j<=n:
l[j]=False
j+=i
i+=1
return l
# lis=[i for i in range(n+1) if l[i] and i>=2]
for n in sys.stdin:
print (prime(int(n))).count(True)-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>
|
s796668380 | p00009 | Accepted | 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 * i, n, i):
prime[j] = False
return [i for i in xrange(2, n) if prime[i]]
while 1:
try:
print len(sieve(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>
|
s426174246 | 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 * i, n, i):
prime[j] = False
return [i for i in xrange(2, n) if prime[i]]
primes = sieve(999999)
while 1:
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>
|
s479388445 | p00009 | Accepted | import bisect
def sieve(n):
a = range(n)
a[0], a[1] = None, None
for i in range(2, n):
if i ** 2 >= n:
break
if a[i] is None:
continue
for j in range(i ** 2, n, i):
a[j] = None
j = 0
for i in range(n):
if a[i] is not None:
a[j] = a[i]
j += 1
return a[0:j]
a = sieve(1000000)
try:
while True:
print bisect.bisect_right(a, int(raw_input()))
except:
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>
|
s300362422 | 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>
|
s651252251 | 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>
|
s371009744 | p00009 | Accepted | from bisect import bisect
n = 10000000
sn = int(n**0.5)+1
num = [False, False] + [True]*(n-1)
for i in xrange(2, int(n**0.5)+1):
if num[i]:
for j in xrange(i**2, n, i):
num[j] = False
prime = [i for i in xrange(2, n) if num[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>
|
s356781786 | p00009 | Accepted | from bisect import bisect
n = 1000000
sn = int(n**0.5)+1
num = [False, False] + [True]*(n-1)
for i in xrange(2, int(n**0.5)+1):
if num[i]:
for j in xrange(i**2, n, i):
num[j] = False
prime = [i for i in xrange(2, n) if num[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>
|
s838854370 | p00009 | Accepted | era = [True]*1000001
for i in xrange(2,1000001):
if era[i-2]:
for j in xrange(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>
|
s075723666 | p00009 | Accepted | while True:
try:
n = int(input())
except:
break
a = [0 for i in range(n + 1)]
# sieve
i = 3
while i * i <= n:
for j in range(3 * i, n + 1, 2 * i): a[j] = 1
i += 2
count = int(n >= 2)
count += sum(a[i] == 0 for i in range(3, n + 1, 2))
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>
|
s817952157 | p00009 | Accepted | a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
for j in range(3 * i, 1000000, 2 * i): a[j] = False
i += 2
while True:
try:
n = int(input())
except:
break
count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
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>
|
s706266410 | p00009 | Accepted | a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
for j in range(3 * i, 1000000, 2 * i): a[j] = False
i += 2
while True:
try:
n = int(input())
except:
break
count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
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>
|
s581564188 | p00009 | Accepted | import sys
def readint():
for line in sys.stdin:
yield int(line)
def getprimes(maxn):
sieve = [0 for i in range(0,maxn+1)]
ps = set()
for p in range(2,maxn+1):
if sieve[p]:
continue
else:
ps.add(p)
for k in range(p,maxn+1,p):
sieve[k] = 1
return ps
ns = [x for x in readint()]
primes = getprimes(max(ns))
for n in ns:
print len(filter(lambda x:n>=x, primes)) | 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>
|
s631006055 | 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>
|
s770655061 | p00009 | Accepted | import math
MAX = 1000000
A = [1]*MAX
for i in range(2,int(math.sqrt(MAX))+1):
if A[i]==1:
for j in range(2*i,MAX,i):
A[j]=0
A[0]=0
A[1]=0
for i in range(1,MAX):
A[i] += A[i-1]
while True:
try:
n = int(input())
except:
break
print(A[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>
|
s949452170 | p00009 | Accepted | import math
while True:
try:
n=int(input())
num=list(range(n+1)) #[0,1,,,,n]が出力される
num[1]=0
for i in range(n):
if num[i]>pow(n,0.5):
break
if num[i]==0:
continue
for j in range(num[i]*2, n+1, num[i]): #num[i]*2からn+1までnum[i]個飛ばしで
num[j]=0
print(n+1-num.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>
|
s849759338 | p00009 | Accepted | a=[1 for i in range(1000001)]
b=[0,0]
a[0]=a[1]=0
c=0
for i in range(2,1000001):
if a[i]==1:
c+=1
for j in range(i * 2,1000001,i):
a[j]=0
b.append(c)
while True:
try:
print(b[int(input())])
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>
|
s595478333 | p00009 | Accepted | n = 1000000
a = [True for i in range(n)]
i = 3
while i * i < n:
for j in range(3 * i, n, 2 * i): a[j] = False
i += 2
while True:
try:
b = int(input())
except:
break
count = int(b >= 2) + sum(a[i] for i in range(3, b + 1, 2))
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>
|
s853736240 | p00009 | Accepted | # coding: utf-8
# Your code here!
a=[1 for i in range(1000001)]
b=[0,0]
a[0]=a[1]=0
c=0
for i in range(2,1000001):
if a[i]==1:
c+=1
for j in range(i*2,1000001,i):
a[j]=0
b.append(c)
while True:
try:
print(b[int(input())])
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>
|
s300003029 | p00009 | Accepted | def sieve(n=10**6):
p=[1]*(n+1)
for i in range(2,n+1):
if p[i]:
for j in range(2*i,n+1,i):p[j]=0
p[0],p[1]=0,0
return p
while True:
try:print(sum(sieve(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>
|
s853704673 | p00009 | Accepted | while True:
try:
n=int(input())
num=list(range(n+1))
num[1]=0
for i in range(n):
if num[i]>n**0.5:
break
if num[i]==0:
continue
for j in range(num[i]*2,n+1,num[i]):
num[j]=0
print(n+1-num.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>
|
s473517895 | p00009 | Accepted | import sys
def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
for e in sys.stdin:
n = int(e)
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>
|
s593292997 | p00009 | Accepted | # coding: utf-8
# Your code here!
MAX = 1000000
s = [1] * MAX
s[0] = 0
s[1] = 0
start = 2
while True:
pmb = 0
for i in range(start, MAX):
if s[i] == 1:
pmb = i
break
if pmb == 0:
break
for i in range(pmb ** 2, MAX, pmb):
s[i] = 0
start += 1
while True:
try:
n = int(input())
c = 0
for i in range(2, n + 1):
if s[i] == 1:
c += 1
print(c)
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>
|
s519248937 | p00009 | Accepted | import math
a = [1]*1000000
for i in range(2,1000000):
for j in range(i+i,1000000)[::i]:
a[j] = 0
b = [0]*1000000
b[0] = b[1] = 0
for i in range(2,1000000):
if a[i] == 1:
b[i] = b[i-1] + 1
else:
b[i] = b[i-1]
while True:
try:
print(b[int(input())])
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>
|
s109586366 | p00009 | Accepted | N = 1000000
p = [1] * N
(p[0],p[1]) = (0,0)
for i in range(N):
if (p[i]):
for j in range (i*2,N,i):
p[j] = 0
for i in range (1,N):
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>
|
s152943860 | p00009 | Accepted | x = [1 for i in range(10 ** 6 + 1)]
x[0] = x[1] = 0
for i in range(10 ** 6 + 1):
if x[i] == 1:
for j in range(i * 2, 10 ** 6 + 1, i):
x[j] = 0
while 0 == 0:
try:
n = int(input())
c = 0
for i in range(n + 1):
c += x[i]
print(c)
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>
|
s839563134 | p00009 | Accepted | while True:
try:
n = int(input())
num = list(range(n + 1))
num[1] = 0
for i in range(n):
if num[i] > n ** 0.5:
break
if num[i] == 0:
continue
for j in range(num[i] * 2, n + 1, num[i]):
num[j] = 0
print(n + 1 - num.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>
|
s281150467 | p00009 | Accepted | def sieve(n=10**6):
p=[1]*(n+1)
for i in range(2,n+1):
if p[i]:
for j in range(2*i,n+1,i):p[j]=0
p[0],p[1]=0,0
return p
while True:
try:print(sum(sieve(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>
|
s703200934 | p00009 | Accepted | # coding: utf-8
LIMIT = 999999
# 1 から LIMIT までのリスト
# 素数(の候補)を 1 、素数でないもを 0 とする
# 2 以外の偶数は素数ではない
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
# 3 から LIMIT の平方根までを走査
for i in range(3, int(LIMIT ** 0.5) + 1):
# 対象が素数である場合
if prime[i - 1] == 1:
# 自身の倍数は素数ではない
for j in range(i ** 2, LIMIT + 1, i):
# 素数ではないので 0
prime[j - 1] = 0
while True:
try:
n = int(input())
except EOFError:
break
# 1 から n までの素数の個数を合計して出力
print(sum(prime[: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>
|
s488468689 | p00009 | Accepted | def prime_checker(n, option = False) -> list:
p = [False, True, False, False, False, True] * (n // 6 + 1)
del p[n + 1:]
p[1 : 4] = False, True, True
for x in range(5, int(n**.5 + 1)):
if p[x]:
p[x * x :: 2*x] = [False] * ((n // x - x) // 2 + 1)
return [e for e, q in enumerate(p) if q] if option else p
from itertools import accumulate
*c, = map(int, open(0))
*p, = accumulate(prime_checker(max(c)))
for i in c:
print(p[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>
|
s492049984 | p00009 | Accepted | import math
while True:
try:
n = int(input())
primes = [1] * (n+1)
for i in range(2, int(math.sqrt(n))+1):
if primes[i] == 1:
for j in range(i*i, n+1, i):
primes[j] = 0
print(sum(primes)-2)
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>
|
s314521131 | p00009 | Accepted | #79 素数の数
import math
while(1):
try:
n = int(input())
except:
break
m = int(math.sqrt(n))
keys = [n // i for i in range(1, m+1)] #1からm+1の間のみn//iを行う
keys += range(keys[-1]-1, 0, -1) #range(始まりの数値,最後の数値,増加量)
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
print(h[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>
|
s179629805 | p00009 | Accepted | import sys
primes = [1] * 500000
primes[0] = 0
for i in range(3, 1000, 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>
|
s293870274 | p00009 | Accepted | kazu=[]
Max=1000000
def era(kazu,Max):
sosu=list(range(2,Max))
while True:
num=sosu[0]
if num>=Max**0.5:
kazu+=sosu
return kazu
kazu.append(num)
sosu=[i for i in sosu if i%num!=0]
era(kazu,Max)
while True:
try:
n=int(input())
if n==1:
print(0)
elif n==2:
print(1)
elif n>=max(kazu):
print(len(kazu))
else:
for i in range(n+1):
if kazu[i]==n:
print(i+1)
break
elif kazu[i]>n:
print(i)
break
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>
|
s043337062 | p00009 | Accepted | import math
def sosu(n) :
for i in range(3, int(math.sqrt(n))+1, 2) :
if n % i == 0 :
return False
return True
S = [0, 0, 1, 2, 2, 3, 3, 4, 4, 4, 4]
for i in range(11, 1000000) :
if i % 2 == 0 :
S.append(S[i-1])
elif sosu(i) :
S.append(S[i-1]+1)
else :
S.append(S[i-1])
while True :
try :
n = int(input())
except EOFError :
break
print(S[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>
|
s457038923 | p00009 | Accepted | import math
def kosu(n):
l=[]
sosu = [True] * (n + 1)
sosu[0]= False
sosu[1]= False
for i in range(2,math.floor(math.sqrt(n))+1):
if not sosu[i]:
continue
for j in range(i*2,n+1,i):
sosu[j] = False
for i in range(len(sosu)):
if sosu[i]:
l.append(i)
return(l)
while True:
try:
n = int(input())
except EOFError:
break
print(len(kosu(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>
|
s808355859 | 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>
|
s937646898 | p00009 | Accepted | def so(x):
a=[]
b=[True]*(n+1)
b[0]=False
b[1]=False
for i in range(2,int(x**0.5)+1):
if not b[i]:
continue
for j in range(i*2,n+1,i):
b[j]=False
for k in range(len(b)):
if b[k]:
a.append(k)
print(len(a))
while True:
try:
n = int(input())
except:
break
so(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>
|
s807565966 | p00009 | Accepted | MAX = 1000000
s = [1]*MAX
s[0] = 0
s[1] = 0
start = 2
while True:
pmb = 0
for i in range(start, MAX):
if s[i] == 1:
pmb = i
break
if pmb == 0:
break
for i in range(pmb**2, MAX, pmb):
s[i] = 0
start += 1
while True:
try:
n = int(input())
c = 0
for i in range(2, n+1):
if s[i] == 1:
c += 1
print(c)
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>
|
s557019111 | p00009 | Accepted | import math
def sosu(n) :
for i in range(3, int(math.sqrt(n))+1, 2) :
if n % i == 0 :
return False
return True
S = [0, 0, 1, 2, 2, 3, 3, 4, 4, 4, 4]
for i in range(11, 1000000) :
if i % 2 == 0 :
S.append(S[i-1])
elif sosu(i) :
S.append(S[i-1]+1)
else :
S.append(S[i-1])
while True :
try :
n = int(input())
except EOFError :
break
print(S[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>
|
s719640473 | p00009 | Accepted | import math
a = [1]*1000000
for i in range(2,1000000):
for j in range(i+i,1000000)[::i]:
a[j] = 0
b = [0]*1000000
b[0] = b[1] = 0
for i in range(2,1000000):
if a[i] == 1:
b[i] = b[i-1] + 1
else:
b[i] = b[i-1]
while True:
try:
print(b[int(input())])
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>
|
s039538925 | p00009 | Accepted | # coding: utf-8
# 79
N=[]
while True:
try:
N.append(int(input()))
except:
break
def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n+ 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
s = primes(max(N))
for k in N:
A=len([x for x in s if x <= k])
print(A)
| 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>
|
s369210029 | p00009 | Accepted | #0009
a = []
l = [2]
while True:
try:
a.append(int(input()))
except:
break
def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
z = primes(max(a))
for k in a:
y = len([x for x in z if x <= k])
print(y)
| 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>
|
s828442813 | p00009 | Accepted | prime=[2]
for i in range(3,1000000,2):
primeq=True
for p in prime:
if i%p==0:
primeq=False
break
if i<p*p:break
if primeq:prime.append(i)
while True:
try:
n=int(input())
ans=0
for p in prime:
if p>n:break
ans+=1
print(ans)
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>
|
s467975399 | p00009 | Accepted | MAX=1000000
B=[]
def P(MAX,B):
A=[i for i in range(2,MAX+1)]
lim=MAX**(1/2)
while True:
p=A[0]
if p>lim:
B+=A
return B
else:
B.append(p)
A=[i for i in A if i%p!=0]
P(MAX,B)
while True:
try:
n=int(input())
if n==1:
print(0)
elif n>=max(B):
print(len(B))
else:
for i in range(n+1):
if B[i]==n:
print(i+1)
break
if B[i]>n:
print(i)
break
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>
|
s586379615 | p00009 | Accepted | import math
while True:
try:
n=int(input())
num=list(range(n+1))
num[1]=0
for i in range(n):
if num[i]>pow(n,0.5):
break
if num[i]==0:
continue
for j in range(num[i]*2, n+1, num[i]):
num[j]=0
print(n+1-num.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>
|
s401963839 | p00009 | Accepted | lst = [1]*999999
for i in range(999999):
if i == 0:
lst[i] = 0
else:
if lst[i] == 1:
j = i +1
k = i
while True:
k = k + j
if k >= 999999:
break
lst[k] = 0
while True:
try:
n = int(input())
anslst = lst[:n]
print(sum(anslst))
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>
|
s311703300 | p00009 | Accepted | #!/usr/bin/env python3
"""Enumerates primes in an interval.
Verification: [0009](https://onlinejudge.u-aizu.ac.jp/status/users/hamukichi/submissions/1/0009/judge/4571021/Python3)
"""
import math
import sys
def segment_sieve(begin, end):
"""Enumerates the prime numbers in [`begin`, `end`).
Returns (as a tuple):
- `is_prime`: a list of bool values.
If an integer `i` is a prime number, then `is_prime[i - begin]` is True.
Otherwise `is_prime[i -begin]` is False.
- `primes`: a list of prime numbers in [`begin`, `end`).
"""
assert 1 < begin <= end
sqrt_end = math.ceil(math.sqrt(end))
is_prime_small = [True for i in range(sqrt_end)]
is_prime_small[0] = False
is_prime_small[1] = False
is_prime = [True for i in range(end - begin)]
for i in range(2, sqrt_end):
if is_prime_small[i]:
for j in range(2 * i, sqrt_end, i):
is_prime_small[j] = False
for k in range(max(2, (begin + i - 1) // i) * i, end, i):
is_prime[k - begin] = False
primes = [i for i, cond in enumerate(is_prime, begin) if cond]
return is_prime, primes
def main():
ns = [int(n) for n in sys.stdin.readlines()]
max_n = max(ns)
begin = 2
is_prime, _ = segment_sieve(begin, max_n + 1)
for n in ns:
print(sum(is_prime[:n + 1 - begin]))
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>
|
s946331964 | p00009 | Accepted | import math
P = []
# 素数一覧リスト
Max = 1000000
def Era(P, Max) :
D = list(range(2, Max))
limit = math.sqrt(Max)
while True :
p = D[0]
if limit <= p :
P += D
return P
P.append(p)
D = [d for d in D if d % p != 0]
# D に含まれる値かつ p で割り切れない値をリスト化
Era(P, Max)
while True :
try :
n = int(input())
if n == 1 :
print(0)
elif n == 2 :
print(1)
elif n >= max(P) :
print(len(P))
else :
for i in range(n + 1) :
if P[i] == n :
print(i + 1)
break
elif P[i] > n :
print(i)
break
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>
|
s468606259 | p00009 | Accepted | # coding: utf-8
# Your code here!
MAX = 1000000
#エラトステネスの篩を用いて素数リストを予め作成する
s = [1] * MAX
## まずは全ての数が素数か不明ということにしておく
## s[2]以降をfor文で1に変換するより、s[0]s[1]を0とする方が繰り返しを使わずに済む
s[0] = 0
s[1] = 0
start = 2
while True:
## はじめにpmbを0で初期化しておかないと、pmb==0という条件に入ることはない
pmb = 0
for i in range(start, MAX):
if s[i] == 1: #素数か否か不明な数の中で最小値を探す
pmb = i
break #見つかったらループを抜ける
#print("リストsの中身", s)
if pmb == 0:
break #素数が見つからなかった
#篩にかける
for i in range(pmb ** 2, MAX, pmb):
s[i] = 0 #素数でない要素を0にする
start += 1
#素数一覧をを表示
# for i in range(2, MAX):
# if s[i] == 1:
# print(i)
while True:
try:
n = int(input())
c = 0
for i in range(2, n + 1):
if s[i] == 1:
c += 1
print(c)
except EOFError:
break
## tryできたときに行いたい処理はtryのインデント内に書く
# c = 0
# for i in range(2, n + 1):
# if s[i] == 1:
# c += 1
# print(c)
| 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>
|
s007227445 | p00009 | Accepted | limit=999999
prime=[0,1]+[0 if i%2==0 else 1 for i in range(3,limit+1)]
for i in range(3,int(limit**0.5)+1):
if prime[i-1]==1:
for j in range(i**2,limit+1,i):
prime[j-1]=0
while True:
try:
n=int(input())
except EOFError:
break
print(sum(prime[: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>
|
s504344354 | p00009 | Accepted | import math
import sys
isPrime=[False, False]
for i in range(2,1000000):
isPrime.append(True)
for i in range(2,int(math.sqrt(1000000))):
if isPrime[i]:
for j in range(i*i, 1000000, i):
isPrime[j]=False
nPrime=[]
cnt=0
for i in range(0,1000000):
if isPrime[i]:
cnt=cnt+1
nPrime.append(cnt)
for l in sys.stdin:
print(nPrime[int(l)])
| 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>
|
s020563685 | p00009 | Accepted | import math
import sys
is_prime = [i for i in range(1000000)]
is_prime[0] = is_prime[1] = False
for i in range(2,1000000):
is_prime[i] = True
for i in range(2,1000000):
if i*i >= 1000000:
break
if is_prime[i]:
for j in range(i*i,1000000,i):
is_prime[j] = False
n_prime = [i for i in range(1000000)]
cnt = 0
for i in range(1000000):
if is_prime[i]:
cnt += 1
n_prime[i] = cnt
a=[]
for i in sys.stdin:
a.append(int(i))
for i in range(0,len(a)):
print(n_prime[a[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>
|
s959548308 | p00009 | Accepted | check = [False,False]
for i in range(0,999998):
check.append(True)
for i in range(2,1000000):
if(check[i]):
for j in range(i*i,1000000,i):
check[j]=False
while True:
try:
ans = 0
a = int(input())
for y in range(0,a+1):
if(check[y]):
ans += 1
print(ans)
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>
|
s164851027 | p00009 | Accepted | is_prime = [False,False]
for i in range(2,1000000):
is_prime.append(True)
for i in range(2,1000000):
if is_prime[i]:
for j in range(i*i,1000000,i):
is_prime[j] = False
n_prime = [0,0]
cnt = int(0)
for i in range(2,1000000):
if is_prime[i]:
cnt += 1
n_prime.append(cnt)
while True:
try:
n = int(input())
print(n_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>
|
s087153584 | p00009 | Accepted | is_prime = [i for i in range(1000000)]
is_prime[0] = is_prime[1] = False
for i in range(2,1000000):
is_prime[i] = True
for i in range(2,1000000):
if i*i >= 1000000:
break
if is_prime[i]:
for j in range(i*i,1000000,i):
is_prime[j] = False
n_prime = [i for i in range(1000000)]
def main():
cnt = 0
for i in range(1000000):
if is_prime[i]:
cnt += 1
n_prime[i] = cnt
while 1:
try:
n = int(input())
print(n_prime[n])
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>
|
s740226107 | p00009 | Accepted | l = [1 for i in range(10 ** 6 + 1)]
l[0] = l[1] = 0
for i in range(10 ** 6 + 1):
if l[i] == 1:
for j in range(i * 2, 10 ** 6 + 1, i):
l[j] = 0
while 0 == 0:
try:
n = int(input())
c = 0
for i in range(n + 1):
c += l[i]
print(c)
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>
|
s727373926 | p00009 | Accepted | import bisect
def make_prime_numbers(n):
"""n以下の素数を列挙したリストを出力する
計算量: O(NloglogN)
入出力例: 30 -> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
"""
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n ** 0.5) + 1):
if not is_prime[i]:
continue
for j in range(2 * i, n + 1, i):
is_prime[j] = False
prime_numbers = [i for i in range(n + 1) if is_prime[i]]
return prime_numbers
prime_numbers = make_prime_numbers(10 ** 6)
while True:
try:
n = int(input())
except:
break
print(bisect.bisect_right(prime_numbers, 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>
|
s402933597 | p00009 | Accepted | # nまでの自然数が素数かどうかを表すリストを返す
# Sieve of Eratosthenes
def makePrimeChecker(n):
isPrime = [True] * (n + 1)
isPrime[0] = False
isPrime[1] = False
for i in range(2, int(n ** 0.5) + 1):
if isPrime[i]:
for j in range(i * i, n + 1, i):
isPrime[j] = False
return isPrime
ls = makePrimeChecker(10**6)
ls_ans = []
while True:
try:
n = int(input())
ls_ans.append(sum(ls[:n+1]))
except:
break
for i in range(len(ls_ans)):
print(ls_ans[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>
|
s243132658 | p00009 | Accepted | def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if is_prime[i] == False:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n+1) if is_prime[i]]
while True:
try:
n = int(input())
print(len(primes(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>
|
s004537872 | p00009 | Accepted | while True:
try:
a = int(input())
primes = [1] * (a+1)
for i in range(2, int(a**0.5)+1):
if primes[i]==1:
for j in range(i*i, a+1, i):
primes[j] = 0
print(sum(primes)-2)
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>
|
s933236217 | p00009 | Accepted | import math
isPrime = [True] * 1000000
primes = []
def eratos(n):
isPrime[0] = isPrime[1] = False
for i in range(2,int(math.sqrt(n))):
if isPrime[i]:
j = 2 * i
while j <= n:
isPrime[j] = False
j = j + i
eratos(999999)
while True:
try:
num = int(input())
ans = 0
for i in range(0,num + 1):
if isPrime[i]:
ans += 1
print(ans)
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>
|
s993257704 | p00009 | Accepted | import sys
inputs = sys.stdin.readlines()
A = [int(i.rstrip('\n')) for i in inputs]
B = sorted(A)
m = B[-1]
P = [2, 3, 5, 7]
for i in range(11, m + 1, 2):
if i % 5 == 0 or i % 7 == 0:
continue
is_prime = True
for p in P:
if p * p > i:
break
if i % p == 0:
is_prime = False
break
if is_prime:
P.append(i)
P.append(1000000)
l = len(P)
for a in A:
for i in range(l):
if P[i] > a:
print(i)
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>
|
s295445751 | p00009 | Accepted | # 準備
num_list = [0] * 1000000
i = 2
cnt = 0
for num in range(2,len(num_list)):
if num_list[i] == -1:
num_list[i] = num_list[i-1]
i += 1
continue
cnt+=1
num_list[i] = cnt
# num_list[i*2::i] = -1
for j in range(i*2,len(num_list),i):
num_list[j] = -1
i += 1
while True:
try:
n = int(input())
except Exception as e:
break
print(int(num_list[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>
|
s296689478 | p00009 | Accepted | # returns the number of prime numbers less than or equal to n
def sieve(n):
prime = [True] * (n+1)
prime[0] = prime[1] = False
count = 0
for i in range(2, n+1):
if prime[i]:
count += 1
for j in range(2*i, n+1, i):
prime[j] = False
return count
while True:
try:
n = int(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>
|
s110945260 | p00009 | Accepted | import sys
array = []
for line in sys.stdin:
array.append(int(line))
max_val = max(array)
prime_list = [1] * max_val
prime_list[0] = 0
prime_list[1] = 0
i = 2
while i < max_val:
for j in range(i * 2, max_val, i):
prime_list[j] = 0
i = i + 1
while i < max_val and prime_list[i] == 0:
i = i + 1
for val in array:
count = sum(prime_list[:val + 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>
|
s632555096 | p00009 | Accepted | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def primes_for(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n + 1):
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
prime_list = primes_for(10**6)
is_prime = [0]*10**6
for n in prime_list:
is_prime[n] = 1
cnt = [0] * 10**6
for i in range(2, 10**6):
if is_prime[i]:
cnt[i] = cnt[i-1] + 1
else:
cnt[i] = cnt[i-1]
while 1:
try:
n = INT()
print(cnt[n])
except:
sys.exit()
| 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>
|
s147411108 | p00009 | Accepted | import sys,math
def prime(n):
a = [0] * (n+1)
for i in range(2, n+1):
isPrime = a[i] == 0
a[i] = a[i-1] + isPrime * 1
if isPrime:
r = slice(i*2, n+1, i)
a[r] =[1 for x in a[r]]
return a
prime = prime(999999)
for i in sys.stdin:
print(prime[int(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>
|
s103132634 | p00009 | Accepted | import sys
def prime(n):
a = [0] * (n + 1)
a[0] = 1
a[1] = 1
i = 2
while n // i >= i:
if a[i] != 0:
i += 1
continue
j = 2 * i
while j <= n:
a[j] = 1
j += i
i += 1
return [i for i, ai in enumerate(a) if ai == 0]
for i in sys.stdin:
print(len(prime(int(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>
|
s442515821 | p00009 | Accepted | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
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
N = 1000000
primes = eratosthenes_sieve(N)
A = [0] * 1000000
for p in primes:
A[p] = 1
acc = list(accumulate(A))
while True:
try:
a = INT()
print(acc[a])
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>
|
s793401512 | p00009 | Accepted | import bisect
num = 1000000
L = [True] * (num+1)
L[0] = False
L[1] = False
for i in range( 2, int(num**0.5)+ 2 ):
if not L[i]:
continue
for j in range(i*2, num+1, i):
L[j] = False
p = [ x for x in range(num+1) if L[x] ]
while True:
try:
n = int(input())
k = bisect.bisect_left(p,n+1)
print(k)
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>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.