submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s883474000
p00009
Accepted
import sys n=1000000 p=[1]*n p[0]=p[1]=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] for l in sys.stdin: print(p[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 &le; <var>n</var> &le; 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>
s989222779
p00009
Accepted
p = [1] * (1000000 + 1) p[0], p[1] = 0, 0 for i in range(2, int(1000000 ** 0.5) + 1): if not p[i]: continue for j in range(2 * i, 1000000 + 1, i): p[j] = 0 while 1: try: n = int(input()) print(sum(p[:n+1])) except: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s460975472
p00009
Accepted
import sys array = [] for i in sys.stdin: array.append(int(i)) m=max(array) prime = [1]*(m+1) prime[0] = prime[1] = 0 for i in range(2,int(m**0.5)+1): if prime[i] == 1: for j in range(i*i, m+1, i): prime [j] = 0 for i in range(len(array)): print(sum(prime[:array[i] + 1]))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s897744406
p00009
Accepted
MAX = 1000000 SQRT = 1000 # sqrt(MAX) prime = [0] * MAX def sieve(): for i in range(3, MAX, 2): prime[i] = 1 for i in range(3, SQRT, 2): if prime[i] == 1: for j in range(i*i, MAX, i): prime[j] = 0 sieve() cnt = [0] * (MAX+1) cnt[2] = f = 1 for i in range(3, MAX, 2): if prime[i]: f += 1; cnt[i] = cnt[i+1] = f while True: try: print(cnt[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 &le; <var>n</var> &le; 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>
s827614001
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 &le; <var>n</var> &le; 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>
s989082900
p00009
Accepted
import math lst = [1 for i in range(1000001)] prime = [0, 0] lst[0] = lst[1] = 0 cnt = 0 for i in range(2,1000001): if lst[i] == 1: cnt += 1 for j in range(i*2,1000001,i): lst[j] = 0 prime.append(cnt) while(True): try: print(prime[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 &le; <var>n</var> &le; 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>
s396949556
p00009
Accepted
N=1000000 n=int(N**0.5) prime=[True for i in range(N)] prime[0],prime[1]=False,False for i in range(4,N,2): prime[i]=False for i in range(3,n,2): if prime[i]==True: for j in range(i*2,N,i): prime[j]=False prime_number=[i for i,j in enumerate(prime) if j==True] while 1: try: number=int(input()) count=0 for i in prime_number: if number<i:break else:count +=1 print(count) 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 &le; <var>n</var> &le; 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>
s396942611
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 &le; <var>n</var> &le; 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>
s750672564
p00009
Accepted
# the sieve of Eratosthenes primes = [1] * 1000000 primes[0] = 0 primes[1] = 0 for i in range(2, 1000): if primes[i]: primes[i*2::i] = [0] * len(primes[i*2::i]) from itertools import accumulate acc_primes = list(accumulate(primes)) for i in range(30): try: n = int(input()) print(acc_primes[n]) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s479196211
p00009
Accepted
def primes(n): ass = [] 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 for i in range(len(is_prime)): if is_prime[i]: ass.append(i) return ass if __name__ == '__main__': while True: try: n = int(input()) ans = primes(n) print(len(ans)) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s541840079
p00009
Accepted
n=1000000 num=[True]*(n+1) num[0]=num[1]=False for i in range(2,int(n**0.5)+1): if num[i]: for j in range(i*2,n+1,i): num[j]=False # 0 1 2 2 3 3 4 # 1 2 3 4 5 6 7 ans=[0]*(n) for i in range(1,n): if num[i]: ans[i]=ans[i-1]+1 else: ans[i]=ans[i-1] while True: try: s=int(input()) except: break print(ans[s])
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 &le; <var>n</var> &le; 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>
s521506691
p00009
Accepted
import math import sys MAX_V = 999999 prime = [1] * (MAX_V+1) prime[0], prime[1] = [0, 0] sum = [0] * (MAX_V+2) for i in range(2, math.ceil(math.sqrt(MAX_V))+1): if prime[i]: for k in range(2*i, MAX_V+1, i): prime[k] = 0 for i in range(MAX_V+1): sum[i+1] = sum[i] + prime[i] for line in sys.stdin.readlines(): print(sum[int(line)+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 &le; <var>n</var> &le; 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>
s649554612
p00009
Accepted
# coding=utf-8 ### ### for atcorder program ### import sys import math import array # math class class mymath: ### pi pi = 3.14159265358979323846264338 ### Prime Number def pnum_eratosthenes(self, n): ptable = [0 for i in range(n+1)] plist = [] for i in range(2, n+1): if ptable[i]==0: plist.append(i) for j in range(i+i, n+1, i): ptable[j] = 1 return plist def pnum_fermat(self,n): pnum = 0 for i in range(2,n+1): if i % 2 == 0 and i != 2: continue if pow(2,i-1,i) == 1: pnum += 1 return pnum ### GCD def gcd(self, a, b): if b == 0: return a return self.gcd(b, a%b) ### LCM def lcm(self, a, b): return (a*b)//self.gcd(a,b) mymath = mymath() ### output class class output: ### list def list(self, l): l = list(l) print(" ", end="") for i, num in enumerate(l): print(num, end="") if i != len(l)-1: print(" ", end="") print() output = output() ### input sample #i = input() #A, B, C = [x for x in input().split()] #N, K = [int(x) for x in input().split()] #inlist = [int(w) for w in input().split()] #R = float(input()) #A = [int(x) for x in input().split()] #for line in sys.stdin.readlines(): # x, y = [int(temp) for temp in line.split()] ### output sample #print("{0} {1} {2:.5f}".format(A//B, A%B, A/B)) #print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi)) #print(" {}".format(i), end="") def main(): for line in sys.stdin.readlines(): n = int(line) n_pn = mymath.pnum_eratosthenes(n) print(len(n_pn)) if __name__ == '__main__': main()
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s297506777
p00009
Accepted
def prime(n, p): cnt = 0 for i in range(n+1): if(p[i]): cnt += 1 return cnt p = [True for i in range(1000001)] p[0] = False p[1] = False for i in range(2, 500001): for j in range(2, 1000000//i + 1): p[i * j] = False while True: try: n = int(input()) except EOFError: break print(prime(n, 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 &le; <var>n</var> &le; 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>
s369554785
p00009
Accepted
import sys def PrimNum(p): i = 0 while True: if len(l) <= i: break if l[i] > p: break i+=1 return i def PrimeList(p) -> list: if p == 2: return 1 elif p > 2: l = list(range(2, p+1)) i = 0 while pow(l[i], 2) <= p: # 2~pまでの数字の表を作って、2からpに向けて一つずつその倍数となる数を消していく。消されずに残っているものは素数である。 # 入力の内の最大数のみを取り出して、この関数にかける。他の値はリストの中から l = [ l[j] for j in range(0, len(l)) if j <= i or l[j] % l[i] != 0] i+=1 return l a = [int(line) for line in sys.stdin] l = PrimeList(max(a)) # 最大値のみを渡す for i in a: print(PrimNum(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 &le; <var>n</var> &le; 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>
s227454549
p00009
Accepted
def IsPrime(arr): arr[0] = 0 arr[1] = 0 i = 2 while i**2 <= len(arr): if arr[i]: for j in range(i*2,len(arr),i): arr[j] = 0 i += 1 return arr num = [] while True: try: line = int(input()) except EOFError: break num.append(line) n_max = max(num) prime_array = IsPrime([1 for i in range(n_max+1)]) for i in range(len(num)): counter = 0 for j in range(num[i]+1): counter += prime_array[j] print(counter)
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 &le; <var>n</var> &le; 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>
s911413570
p00009
Accepted
import bisect def ifprime(n): for i in range(3,int(n**0.5)+1): if n%i==0:return(False) return(True) prime_list=[2,3] while 1: try: n=int(input()) if n>prime_list[-1]+1: for i in range(prime_list[-1]+2,n+1,2): if ifprime(i):prime_list.append(i) x=bisect.bisect_left(prime_list,n+1) print(x) 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 &le; <var>n</var> &le; 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>
s609006929
p00009
Accepted
numbers=[] for i in range(1000000): numbers.append(True) numbers[0]=False numbers[1]=False idx=1 multiple=1 while True: idx+=1 multiple=idx if idx>1000000**(1/2): break while True: if 999999<idx*multiple: break numbers[idx*multiple]=False multiple+=1 #print(numbers) def count(n):#関数「count」を定義 cnt=0 for i in range(n+1): if numbers[i]==True: cnt+=1 print(cnt) while True: try: n=int(input()) count(n) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s166143146
p00009
Accepted
is_prime=[True for i in range(1000000+1)] is_prime[0]=is_prime[1]=False for i in range(2,1000): if not is_prime[i]: continue for j in range(2,int(1000000/i)+1): is_prime[i*j]=False cnt=0 primepi=[0 for i in range(1000000)] for i in range(1000000): if is_prime[i]: cnt+=1 primepi[i]=cnt while True: try: n = int(input()) except EOFError: break print(primepi[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 &le; <var>n</var> &le; 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>
s784172566
p00009
Accepted
MAX = 1000000 # 素数の表 prime_map = [True] * MAX prime_map[0] = False prime_map[1] = False # n以下の素数の表 prime_num_map = [0] * MAX for i in range(2, MAX): if prime_map[i]: prime_num_map[i] = prime_num_map[i-1] + 1 index = 2 n = i*index while n < MAX: prime_map[n] = False index += 1 n = i*index else: prime_num_map[i] = prime_num_map[i-1] while True: try: n = int(input()) print(prime_num_map[n]) except: exit(0)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s463827138
p00009
Accepted
import sys import math MAXNUM=1000000 SQRT=math.sqrt(MAXNUM) def eratosthenes(): l = [1]*MAXNUM l[0:2]=[0]*2 l[4:MAXNUM:2] = [0]*len(l[4:MAXNUM:2]) for i in range(3,1000,2): l[i*i:MAXNUM:i*2] = [0]*len(l[i*i:MAXNUM:i*2]) return l primes = eratosthenes() for i in sys.stdin: n = int(i) print(sum(primes[0:n+1]))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s274781752
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 &le; <var>n</var> &le; 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>
s580259233
p00009
Accepted
import math def prime(n): plist = [1 for i in range(n)] pivot = int(math.sqrt(n)) plist[0] = 0 if n <= 1: return 0 if n == 2: return 1 if n == 3: return 2 else: for i in range(2,pivot+1): if plist[i-1] == 0: continue else: for j in range(2*i,n+1,i): plist[j-1] = 0 psum = sum(plist) return psum import sys while True: line = sys.stdin.readline() if not line: break n = int(line.rstrip('\r\n')) print(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 &le; <var>n</var> &le; 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>
s417508198
p00009
Accepted
max_n = 999999 prime_list = [1] * (max_n + 1) # 0, 1は素数ではない prime_list[0:2] = [0, 0] # for i in range(2, int(max_n**0.5) + 1): if prime_list[i] == 1: prime_list[i**2::i] = [0] * len(prime_list[i**2::i]) while True: try: n = int(input()) print(sum(prime_list[: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 &le; <var>n</var> &le; 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>
s434499514
p00009
Accepted
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)] keys += range(keys[-1]-1, 0, -1) h = {i: i-1 for i in keys} for i in range(2, m+1): if h[i] > h[i-1]: hp = h[i-1] i2 = i*i for j in keys: if j < i2: break h[j] -= h[j // i] - hp 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 &le; <var>n</var> &le; 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>
s735199469
p00009
Accepted
M = 10**6 p = [0]*(M+60) sM = M**0.5 for x in range(1, int(sM/2)+1): v = 4*x*x + 1; y = 8 while v <= M: if v % 12 != 9: # v % 12 in [1, 5] p[v] ^= 1 v += y; y += 8 for x in range(1, int(sM/3**0.5)+1, 2): v = 3*x*x + 4; y = 12 while v <= M: if v % 12 == 7: p[v] ^= 1 v += y; y += 8 for x in range(2, int(sM/2**0.5)+1): v = 2*x*(x+1)-1; y = 4*x-8 while 0 <= y and v <= M: if v % 12 == 11: p[v] ^= 1 v += y; y -= 8 for n in range(5, int(sM)+1): if p[n]: for z in range(n*n, M, n*n): p[z] = 0 p[2] = p[3] = 1 c = [0]*M cnt = 0 for i in range(M): if p[i]: cnt += 1 c[i] = cnt while 1: try: n = int(input()) except: break print(c[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 &le; <var>n</var> &le; 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>
s455040375
p00009
Accepted
def get_prime_set(ub): from itertools import chain from math import sqrt if ub < 4: return ({}, {}, {2}, {2, 3})[ub] ub, ub_sqrt = ub+1, int(sqrt(ub))+1 primes = {2, 3} | set(chain(range(5, ub, 6), range(7, ub, 6))) du = primes.difference_update for n in chain(range(5, ub_sqrt, 6), range(7, ub_sqrt, 6)): if n in primes: du(range(n*3, ub, n*2)) return primes import sys from bisect import bisect_right primes = list(get_prime_set(999999)) print(*(bisect_right(primes, int(n)) for n in sys.stdin), sep="\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 &le; <var>n</var> &le; 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>
s263705307
p00009
Accepted
def pi_x(n): ''' pi_x(n)[i] = pi(i)となるようにする エラトステネスの篩→O(n log log n) ''' prime = [] is_prime = [True] * (n + 1) #is_prime[i] = Trueならiは素数 is_prime[0] = False is_prime[1] = False for i in range(2, n+1): if is_prime[i]: prime.append(i) for j in range(2 * i, n + 1, i): is_prime[j] = False prime_accum = [0] * (n + 1) for i in range(1, n + 1): prime_accum[i] = prime_accum[i - 1] + is_prime[i] return prime_accum import sys P = pi_x(10 ** 6) a = [] for line in sys.stdin: a.append(int(line)) for num in a: print(P[num])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s763296139
p00009
Accepted
PN = [i for i in range(1000000)] #print(PN[0:20]) i = 2 while True: if i >= len(PN): break j = i * 2 while True: if j >= len(PN): break PN[j] = 0 j += i while True: i += 1 if i >= len(PN): break if PN[i] != 0: break PN[1] = 0 #print(PN[0:20]) cntPN = [] for i in range(1000000): if i == 0: cntPN.append(0) elif PN[i] == 0: cntPN.append(cntPN[i - 1]) else: cntPN.append(cntPN[i - 1] + 1) #print(cntPN[0:20]) import sys a = [] for line in sys.stdin: a.append(int(line)) for i in a: print(cntPN[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 &le; <var>n</var> &le; 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>
s508719902
p00009
Accepted
from math import sqrt, ceil N = 1000000 temp = [True]*(N+1) temp[0] = temp[1] = False for i in range(2, ceil(sqrt(N+1))): if temp[i]: temp[i+i::i] = [False]*(len(temp[i+i::i])) while True: try:print(len([1 for _ in temp[:int(input())+1] if _])) 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 &le; <var>n</var> &le; 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>
s404920172
p00009
Accepted
import math import sys sup = 1000000 is_prime = [0] * sup count = [0] * sup def setup(): is_prime[2] = 1 for n in range(3,sup,2): flag = True for i in range(3, int(math.floor(math.sqrt(n) + 1)), 2): if n % i == 0: flag = False break if flag: is_prime[n] = 1 def precount(): for n in range(2, sup): count[n] = count[n-1] + is_prime[n] def main(): setup() precount() l = [] for line in sys.stdin: l.append(int(line)) for line in l: print(count[line]) 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 &le; <var>n</var> &le; 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>
s109888873
p00009
Accepted
def eratosthenes(n): multiples = set() for i in range(2, n+1): if i not in multiples: yield i multiples.update(range(i*i, n+1, i)) while True: try: print(len(list(eratosthenes(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 &le; <var>n</var> &le; 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>
s751503786
p00009
Accepted
import math n = 1000001 rn = round(math.sqrt(n)) + 1 tbl = [True for i in range(n)] tbl[0], tbl[1] = False,False for i in range(4,n,2): tbl[i] = False for i in range(3,rn,2): if tbl[i]: for j in range(i*2,n,i): tbl[j] = False n = int(input()) while 1: print(sum(tbl[:n+1])) try: n = 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 &le; <var>n</var> &le; 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>
s536237538
p00009
Runtime Error
import math def prime_calc(n): if n < 2: return False elif n==2 or n==3 or n==5 or n==7: return True else: rootN = math.floor(math.sqrt(n)) i = 11 while rootN > i: if n % i == 0: return False else: i += 2 return True def prime(n): cnt = 0 for i in range(2, n+1): ans = prime_calc(i) if ans is True: cnt = cnt + 1 return cnt def main(): l = [] for line in sys.stdin: l.append(int(line)) for line in l: print(prime(line)) 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 &le; <var>n</var> &le; 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>
s067806104
p00009
Runtime Error
import math import sys def prime_calc(n): rootN = math.floor(math.sqrt(n)) prime = [2] data = [i + 1 for i in range(2,n,2)] while True: p = data[0] if rootN < p: return len(prime + data) prime.append(p) data = [e for e in data if e % p != 0] def main(): l = [] for line in sys.stdin: l.append(line) for line in l: print(prime_calc(line)) 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 &le; <var>n</var> &le; 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>
s944920939
p00009
Runtime Error
import math import sys def prime_calc(n): rootN = math.floor(math.sqrt(n)) prime = [2] data = [i + 1 for i in range(2,n,2)] while True: p = data[0] if rootN <= p: return len(prime + data) prime.append(p) data = [e for e in data if e % p != 0] def main(): l = [] for line in sys.stdin: l.append(line) for line in l: print(prime_calc(line)) 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 &le; <var>n</var> &le; 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>
s885090952
p00009
Runtime Error
import math import sys def prime_calc(n): rootN = int(n**0.5) prime = [2] data = [i + 1 for i in range(2,n,2)] while True: p = data[0] if rootN <= p: return len(prime + data) prime.append(p) data = [e for e in data if e % p != 0] def main(): l = [] for line in sys.stdin: l.append(line) for line in l: print(prime_calc(line)) 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 &le; <var>n</var> &le; 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>
s261737122
p00009
Runtime Error
import math import sys def prime_calc(n): rootN = math.floor(math.sqrt(n)) prime = [2] data = [i + 1 for i in range(2,n,2)] while True: p = data[0] if rootN <= p: return len(prime + data) prime.append(p) data = [e for e in data if e % p != 0] def main(): l = [] for line in sys.stdin: l.append(line) for line in l: print(prime_calc(line)) 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 &le; <var>n</var> &le; 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>
s807101510
p00009
Runtime Error
import math import sys def prime_calc(n): rootN = math.floor(math.sqrt(n)) prime = [2] data = [i + 1 for i in range(2,n,2)] while True: p = data[0] if rootN <= p: return len(prime + data) prime.append(p) data = [e for e in data if e % p != 0] def main(): l = [] for line in sys.stdin: l.append(int(line)) for line in l: print(prime_calc(line)) 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 &le; <var>n</var> &le; 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>
s631007833
p00009
Runtime Error
import sys import math def prime_calc(n): rootN = math.floor(math.sqrt(n)) prime = [2] data = [i + 1 for i in range(2,n,2)] while True: p = data[0] if rootN < p: return len(prime + data) prime.append(p) data = [e for e in data if e % p != 0] def main(): l = [] for line in sys.stdin: l.append(int(line)) for line in l: print(prime_calc(line)) 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 &le; <var>n</var> &le; 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>
s180259448
p00009
Runtime Error
while True: sum=0 n=input() i=1 j=2 if n==3:sum=2 else : while i<=n: while j<i: if i%j==0:break j+=1 if i==j:sum+=1 if n%2==0:i+=2 elif n%2!=0 and i==n-2:i+=1 else :i+=2 print sum
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 &le; <var>n</var> &le; 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>
s702175958
p00009
Runtime Error
num=1000000 prime=[1]*1000000 i=2 ans=0 while i<1000000: if prime[i]==1: ans+=1 if i<1000: j=i*i while j<1000000: prime[j]=0 j+=i prime[i]=ans i+=1 while True: n=input() print 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 &le; <var>n</var> &le; 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>
s830732859
p00009
Runtime Error
num=1000000 prime=[1]*1000000 prime[0]=0 prime[1]=0 i=2 ans=0 while i<1000000: if prime[i]==1: ans+=1 if i<1000: j=i*i while j<1000000: prime[j]=0 j+=i prime[i]=ans i+=1 while True: n=input() print 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 &le; <var>n</var> &le; 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>
s797688621
p00009
Runtime Error
num=1000000 prime=[1]*1000000 prime[0]=0 prime[1]=0 i=2 ans=0 while i<1000000: if prime[i]==1: ans+=1 if i<1000: j=i*i while j<1000000: prime[j]=0 j+=i prime[i]=ans i+=1 while True: n=input() try: print prime[n] except: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s632146392
p00009
Runtime Error
num=1000000 prime=[1]*1000000 prime[0]=0 prime[1]=0 i=2 ans=0 while i<1000000: if prime[i]==1: ans+=1 if i<1000: j=i*i while j<1000000: prime[j]=0 j+=i prime[i]=ans i+=1 while True: try: n=input(): print prime[n] except: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s302976155
p00009
Runtime Error
# PrimeNumber from itertools import product import math def nOfPrime(m): return m * 2 if __name__ == "__main__": while True: try: n = int(input()) prm = 1 nlist = [] nlist2 = [] plist = [] for i in range(2, n + 1): nlist.append(i) # [2,3,4,5,6,...,n] while True: #print(nlist, " ", math.sqrt(n)) if nlist[0] > math.sqrt(n): # 終了条件 #plist.append(map(int,nlist)) plist.extend(nlist) break; else: plist.append(nlist[0]) #i = 0 for j in nlist: if j % nlist[0] != 0: #nlist.pop(i) #nlist.remove(j) nlist2.append(j) #i += 1 nlist = nlist2 nlist2 = [] #print("fin: {}".format(plist)) print(len(plist)) except EOFError: break # escape from while loop 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 &le; <var>n</var> &le; 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>
s820709123
p00009
Runtime Error
# PrimeNumber from itertools import product import math if __name__ == "__main__": while True: try: n = int(input()) nlist = [] nlist2 = [] plist = [] for i in range(2, n + 1): nlist.append(i) # [2,3,4,5,6,...,n] while True: #print(nlist, " ", math.sqrt(n)) if nlist[0] > math.sqrt(n): # 終了条件 #plist.append(map(int,nlist)) plist.extend(nlist) break; else: plist.append(nlist[0]) #i = 0 for j in nlist: if j % nlist[0] != 0: #nlist.pop(i) #nlist.remove(j) nlist2.append(j) #i += 1 nlist = nlist2 nlist2 = [] #print("fin: {}".format(plist)) print(len(plist)) except EOFError: break # escape from while loop 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 &le; <var>n</var> &le; 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>
s557591073
p00009
Runtime Error
# PrimeNumber # エラトステネスの篩 from itertools import product import math if __name__ == "__main__": while True: try: # 数値の入力があった n = int(input()) nlist = [] nlist2 = [] plist = [] # for i in range(2, n + 1): # nlist.append(i) # [2,3,4,5,6,...,n] nlist = range(2, n + 1, 1) while True: #print(nlist, " ", math.sqrt(n)) sqrtn = math.sqrt(n) if nlist[0] > sqrtn: # 終了条件 #plist.append(map(int,nlist)) plist.extend(nlist) break else: plist.append(nlist[0]) #i = 0 for j in nlist: if j % nlist[0] != 0: #nlist.pop(i) #nlist.remove(j) nlist2.append(j) #i += 1 nlist = nlist2 nlist2 = [] #print("fin: {}".format(plist)) print(len(plist)) except EOFError: break # escape from while loop 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 &le; <var>n</var> &le; 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>
s201996930
p00009
Runtime Error
# PrimeNumber # エラトステネスの篩 from itertools import product import math if __name__ == "__main__": while True: try: # 数値の入力があった n = int(input()) nlist = [] nlist2 = [] plist = [] # for i in range(2, n + 1): # nlist.append(i) # [2,3,4,5,6,...,n] nlist = range(3, n + 1, 2) while True: #print(nlist, " ", math.sqrt(n)) sqrtn = math.sqrt(n) if nlist[0] > sqrtn: # 終了条件 #plist.append(map(int,nlist)) plist.extend(nlist) break else: plist.append(nlist[0]) #i = 0 for j in nlist: if j % nlist[0] != 0: #nlist.pop(i) #nlist.remove(j) nlist2.append(j) #i += 1 nlist = nlist2 nlist2 = [] #print("fin: {}".format(plist)) print(len(plist)+1) # 2の分を追加 except EOFError: break # escape from while loop 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 &le; <var>n</var> &le; 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>
s636571932
p00009
Runtime Error
# PrimeNumber # エラトステネスの篩 import math if __name__ == "__main__": while True: try: # 数値の入力があった n = int(input()) nlist = [] nlist2 = [] plist = [] # for i in range(2, n + 1): # nlist.append(i) # [2,3,4,5,6,...,n] nlist = range(3, n + 1, 2) while True: #print(nlist, " ", math.sqrt(n)) sqrtn = math.sqrt(n) if nlist[0] > sqrtn: # 終了条件 #plist.append(map(int,nlist)) plist.extend(nlist) break else: plist.append(nlist[0]) #i = 0 for j in nlist: if j % nlist[0] != 0: #nlist.pop(i) #nlist.remove(j) nlist2.append(j) #i += 1 nlist = nlist2 nlist2 = [] #print("fin: {}".format(plist)) print(len(plist)+1) # 2の分を追加 except EOFError: break # escape from while loop 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 &le; <var>n</var> &le; 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>
s302562083
p00009
Runtime Error
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<vector> using namespace std; const int MAXN=1000001; bool p[MAXN]; vector<int> a; int main(){ memset(p,false,sizeof(p)); for (int i=2;i<sqrt(MAXN);i++) for (int j=i+i;j<MAXN;j+=i) p[j]=true; for (int i=2;i<MAXN;i++) if (!p[i]) a.push_back(i); int n; while (cin >> n){ vector<int>::iterator f=lower_bound(a.begin(),a.end(),n); if (*f==n) cout << f-a.begin()+1 << endl; else cout << f-a.begin() << endl; } return 0; }
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s831462178
p00009
Runtime Error
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] = p[1] = 0 i = 2 while i*i < n: if p[i]: p[2*i::i] = [0 for x in range(2*i,R,i)] i += p[i+1:].index(1)+1 for i in n: print sum(p[:i+1])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s965173443
p00009
Runtime Error
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] = p[1] = 0 i = 2 while i*i <= R: if p[i]: p[2*i::i] = [0 for x in range(2*i,R,i)] i += p[i+1:].index(1)+1 for i in n: print sum(p[:i+1])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s322800866
p00009
Runtime Error
n = [] while True: try: n.append(int(raw_input())) except: break R = max(n)+1 p = [1]*R p[0] = p[1] = 0 i = 2 while i <= R**0.5: if p[i]: p[2*i::i] = [0]*((R-2*i)/i) i += p[i+1:].index(1)+1 for i in n: print sum(p[:i+1])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s323886204
p00009
Runtime Error
% cat test.py n = [] while True: try:n.append(int(raw_input())) except:break R = max(n)+10 p = [1]*R p[0] = p[1] = 0 p[4::2] = [0 for i in range(4,R,2)] for i in range(3,int(R**0.5),2): if p[i]: p[2*i::i] = [0]*len(p[2*i::i]) print p for i in n: print sum(p[:i+1])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s035135957
p00009
Runtime Error
n = [] while True: try:n.append(int(raw_input())) except:break R = max(n)+1 p = [1]*R p[0] = p[1] = 0 p[4::2] = [0 for i in range(4,R,2)] for i in range(3,int(R**0.5)+1,2): if p[i]: p[2*i::i] = [0]*((R-2*i+1)/i) for i in n: print sum(p[:i+1])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s713940170
p00009
Runtime Error
rom bisect import bisect R = 1000000 p = [1]*R p[0] = p[1] = 0 p[4::2] = [0]*len(p[4::2]) for i in xrange(3,int(R**0.5)+1,2): if p[i]: p[i*i::i] = [0]*len(p[i*i::i]) prime = [i for i in xrange(2,R) if p[i]] while True: try:print bisect(prime,input()) except:break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s684982843
p00009
Runtime Error
# -*- coding;utf-8 -*- def sieve(n): p = 0 primes = [] is_prime = [True]*(n+1) is_prime[0] = False is_prime[1] = False for i in range(2, n+1): if(is_prime[i]): primes.append(i) p += 1 for j in range(i*2,n,i):#iごとに増える is_prime[j] = False return p if(__name__ == "__main__"): while(True): try: n = int(input()) except: break print(sieve(n) + "\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 &le; <var>n</var> &le; 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>
s330996880
p00009
Runtime Error
def pri(n): s=[True for _ in range(n+1)] i=2 while i**2<=n: if s[i]: j=i*2 while j<=n: s[j]=False j+=i i+=1 tab=[i for i in range(n+1) if s[i] and i>=2] return(tab) while True: try; print(len(pri(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 &le; <var>n</var> &le; 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>
s872551343
p00009
Runtime Error
import sys for n in sys.stdin: n=int(n) x=[0]*n x[2]=1 flag = 0 for i in xrange(3,n): flag = 0 for j in [p for p in xrange(1,(i/2)+1) if x[p]!=0]: if (i%j == 0): flag = 1 break if flag==0: x[i]=1 print len([v for v in xrange(n) if x[v]==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 &le; <var>n</var> &le; 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>
s509300811
p00009
Runtime Error
import sys n=999999 prime = [1]*(n+1) (prime[0],prime[1])=(0,0) for i in xrange(2,n+1): if type(i*i)==int: for j in xrange(i*i,n+1,i): prime[j]=0 for n in sys.stdin: print prime[:n-1].count(1)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s894580153
p00009
Runtime Error
import sys n=999999 prime = [1]*(n+1) (prime[0],prime[1])=(0,0) for i in xrange(2,n+1): if i*i<n+1: for j in xrange(i*i,n+1,i): prime[j]=0 for inp in sys.stdin: print prime[:inp-1].count(1)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s690862230
p00009
Runtime Error
import math def pri(n): if n < 2: return False elif n == 2: return True elif n % 2 == 0: return False i = 3 while i <= math.sqrt(n): if n % i == 0: return False i += 2 return True l=[i for i in range(110000)if pri(i) ] while True: n = int(input()) if n == 0: break print(sum(l[: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 &le; <var>n</var> &le; 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>
s173538266
p00009
Runtime Error
#coding: UTF-8 from bisect import bisect_right # 指定した数以下の素数の個数を返却する # 素数判定はエラストテネスのふるい # 要素1000000のリスト(素数かどうかのリスト)を準備 max_number = 1000000 prime_flag_list = [True] * max_number # 0、1は素数でない prime_flag_list[0] = False prime_flag_list[1] = False # 2の倍数(2を除く)は素数でない prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2]) # 3以上の数について、素数ならその倍数を振るい落とす for i in range(3, int(max_number**0.5) + 1, 2): prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i]) # フラグの立ったままの箇所は素数なので、そこだけ取り出す prime_list = [i for i in range(2, max_number) if prime_flag_list[i]] while True: try: input = int(raw_input()) except EOFError: break # 素数リスト(ソート済み)の中に、入力した数値を入れるとしたら何項目目になるかを # bisectで求める print bisect.bisect_right(prime_list, input)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s536318100
p00009
Runtime Error
for input in sys.stdin: prime_num = 0 for i in range(int(input)): y = i+1 x = y / 2 while x > 1: if y % x == 0: break x -= 1 else: prime_num += 1 print(prime_num-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 &le; <var>n</var> &le; 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>
s570103225
p00009
Runtime Error
import math def pi(n): m = int(math.sqrt(n)) keys = [n / i for i in range(1, m + 1)] keys += range(keys[-1] - 1, 0, -1) h = {i : i - 1 for i in keys} for i in range(2, m + 1): if h[i] > h[i - 1]: hp = h[i - 1] i2 = i * i for j in keys: if j < i2: break h[j] -= h[j / i] - hp return h[n] while 1: i = int(raw_input()) print pi(i)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s050390460
p00009
Runtime Error
def checkPrime(number): if number == 2: return True if number % 2 == 0: return False i = 3 while (i ** 2 < number + 1): if number % i == 0: return False i += 2 return True p = [True for i in range(0, 1000000)] p[0] = 0 p[1] = 0 for i in range(2, len(p)): p[i] = p[i - 1] if checkPrime(i): p[i] += 1 while True: print(p[int(input())])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s987254168
p00009
Runtime Error
import sys l = [True] * 100000 for i in range(2, 100000): if (l[i - 1]): for j in range(i ** 2 - 1, 100000, i): l[j] = False n = [int(line) for line in sys.stdin] for nn in n: print(l[1:int(n)].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 &le; <var>n</var> &le; 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>
s567951252
p00009
Runtime Error
import math num_max = 999999 i = 3 prime_list = [2] while i<num_max : judge = True j = 0 while prime_list[j] <= math.sqrt(i) : if (i%prime_list[j]==0) : judge = False break j += 1 if(judge) : prime_list.append(i) i += 2 while True : try: n = input() k = 0 while prime_list[k] <= n : k += 1 print(k) 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 &le; <var>n</var> &le; 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>
s623726429
p00009
Runtime Error
#!/usr/bin/python # import time import sys def sieve(n): num = [1]*n num[0] = num[1] = 0 for i in xrange(2,int(n**0.5)+1): if num[i]: for j in xrange(i**2, n, i): num[j] = 0 return num.count(1) # start = time.time() for line in sys.stdin: hoge = sieve(int(line)) print hoge # elapsed_time = time.time()-start # print elapsed_time # print hoge
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 &le; <var>n</var> &le; 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>
s631439862
p00009
Runtime Error
import sys import math for line in sys.stdin: Nmax=int(line)+1 list=range(2,Nmax) fNmax=float(Nmax) SQmax=math.floor(math.sqrt(fNmax)) scnt=0 for i in xrange(0,int(SQmax)): cnt=2 if list[i]!=0: while list[i]*cnt < Nmax: list[(list[i]*cnt)-2]=0 cnt+=1 while 0 in list: list.remove(0) # print list print len(list)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s778666329
p00009
Runtime Error
def solve(n): A=[0 for i in range(n+1)] A[2]=1 for i in range(2,n+1): cnt=0 for j in range(1,i+1,2): if i%j==0: cnt+=1 if cnt==2:#1??¨????????°?????? A[i]=1 return sum(A) while True: try: n = int(input()) print(solve(n)) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s553078604
p00009
Runtime Error
def sieve(n): p=[True]*(n+1) p[0]=p[1]=False for i in range(2,n+1,2): if p[i]==True: for j in range(i*i,n+1,i): p[j]=False return p def solve(n): if n<2:return 0 c=1 for i in range(3,n+1,2): if p[i]==1: c+=1 return c p=sieve(100000) while True: try: n = int(input()) print(solve(n)) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s830731626
p00009
Runtime Error
def sieve(n): p=[True]*(n+1) p[0]=p[1]=False for i in range(2,n+1,2): if p[i]==True: for j in range(i*i,n+1,i): p[j]=False return p def solve(n): if n<2:return 0 c=1 for i in range(3,n+1,2): if p[i]==1: c+=1 return c p=sieve(1e6) while True: try: n = int(input()) print(solve(n)) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s378580024
p00009
Runtime Error
# -*- coding: utf-8 -*- import sys def isPrime(p): if p == 2: return True elif p < 2 or p%2 == 0: return False elif pow(2, p-1, p) == 1: return True else: return False for line in sys.stdin: n = int(line) count = 0 for i in range(n): if isPrime(int(raw_input())): 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 &le; <var>n</var> &le; 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>
s453002393
p00009
Runtime Error
# coding: utf-8 import math import sys def prime(number): count = 0 for i in range(int(math.sqrt(number))): if number % i != 0: count += 1 return count data = [] for line in sys.stdin: data.append(int(line)) for num in data: print prime(num)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s343356841
p00009
Runtime Error
a=int(input()) X=[i for i in range(2,a+1)] while True: X=[i for i in X if i % Y[0] !=0 ] if X == Y: break Y=X[:] print(len(X))
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 &le; <var>n</var> &le; 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>
s773417767
p00009
Runtime Error
a=int(input()) X=[i for i in range(2,a+1)] while True: X=[i for i in X if i % X[0] !=0 ] if X == Y: break Y=X[:] print(len(X))
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 &le; <var>n</var> &le; 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>
s632131899
p00009
Runtime Error
for c in range(0,3) a=int(input()) X=[i for i in range(2,a+1)] Y=[] while True: X=[i for i in X if i % X[0] !=0 ] if X == Y: break Y=X[:] print(len(X))
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 &le; <var>n</var> &le; 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>
s293811371
p00009
Runtime Error
for c in range(0,3): a=int(input()) X=[i for i in range(2,a+1)] Y=[] while True: X=[i for i in X if i % X[0] !=0 ] if X == Y: break Y=X[:] print(len(X))
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 &le; <var>n</var> &le; 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>
s274692743
p00009
Runtime Error
while True: a=int(input()) X=[i for i in range(2,a+1)] Y=[] while True: X=[i for i in X if i % X[0] !=0 ] if X == Y: break Y=X[:] print(len(X))
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 &le; <var>n</var> &le; 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>
s649267919
p00009
Runtime Error
while True: a=int(input()) X=[i for i in range(2,a+1)] Y=[] while True: k=X[0] X=[i for i in X if i % k !=0] Y.append(k) if len(X)==0: break print(len(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 &le; <var>n</var> &le; 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>
s321023339
p00009
Runtime Error
from math import * search_list = [] prime_list = [] target = 0 def get_input(): while True: try: yield ''.join(input()) except EOFError: break if __name__ == '__main__': array = list(get_input()) for i in range(len(array)): #??\????????¨?????????????????????????????§?´???°????????°?????¢?´¢?????? for j in range(2,int(array[i])+1): #??¢?´¢?????????????????? search_list.append(j) #print(sqrt(int(array[i]))) while True: if target > sqrt(int(array[i])): prime_list = prime_list + search_list break prime_list.append(search_list[0]) target = search_list[0] search_list.pop(0) k = 1 while target*k<=search_list[-1]: #print(target * k) if target*k in search_list: search_list.remove(target*k) k += 1 #print(search_list) #print(str(array[i]) + "??\???????´???°???" + str(prime_list) + "??????????????°???" + str(len(prime_list))) print(len(prime_list)) target = 0 prime_list.clear() search_list.clear()
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 &le; <var>n</var> &le; 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>
s030774487
p00009
Runtime Error
from math import * search_list = [] prime_list = [] target = 0 def get_input(): while True: try: yield ''.join(input()) except EOFError: break if __name__ == '__main__': array = list(get_input()) for i in range(len(array)): #??\????????¨?????????????????????????????§?´???°????????°?????¢?´¢?????? for j in range(2,int(array[i])+1): #??¢?´¢?????????????????? search_list.append(j) #print(sqrt(int(array[i]))) while True: if target > sqrt(int(array[i])): prime_list = prime_list + search_list break prime_list.append(search_list[0]) target = search_list[0] search_list.pop(0) k = 1 while target*k<=search_list[-1]: #print(target * k) if target*k in search_list: search_list.remove(target*k) k += 1 #print(search_list) #print(str(array[i]) + "??\???????´???°???" + str(prime_list) + "??????????????°???" + str(len(prime_list))) print(len(prime_list)) target = 0 k = 0 prime_list.clear() search_list.clear()
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 &le; <var>n</var> &le; 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>
s118079739
p00009
Runtime Error
from math import * search_list = [] prime_list = [] target = 0 def get_input(): while True: try: yield ''.join(input()) except EOFError: break if __name__ == '__main__': array = list(get_input()) for i in range(len(array)): for j in range(2,int(array[i])+1): search_list.append(j) while True: if target > sqrt(int(array[i])): prime_list = prime_list + search_list break prime_list.append(search_list[0]) target = search_list[0] search_list.pop(0) k = 1 while target*k<=search_list[-1]: if target*k in search_list: search_list.remove(target*k) k += 1 print(len(prime_list)) target = 0 k = 0 prime_list.clear() search_list.clear()
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 &le; <var>n</var> &le; 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>
s696085215
p00009
Runtime Error
from math import * search_list = [] prime_list = [] target = 0 def get_input(): while True: try: yield ''.join(input()) except EOFError: break if __name__ == '__main__': array = list(get_input()) for i in range(len(array)): for j in range(2,int(array[i])+1): search_list.append(j) while True: if target > sqrt(int(array[i])): prime_list = prime_list + search_list break prime_list.append(search_list[0]) target = search_list[0] search_list.pop(0) k = 1 while target*k<=search_list[-1]: if target*k in search_list: search_list.remove(target*k) k += 1 print(len(prime_list)) target = 0 k = 0 del prime_list[:] del search_list[:]
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s471715015
p00009
Runtime Error
import math import sys def get_primes(n): search = list(range(2, n+1)) primes = [] while True: primes.append(search[0]) for i,x in enumerate(search): if x % primes[-1] == 0: del search[i] if search[0] >= math.sqrt(n): primes.extend(search) return primes for line in sys.stdin.readlines(): n = int(line) print(len(get_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 &le; <var>n</var> &le; 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>
s039576640
p00009
Runtime Error
import math import sys def get_primes(n): search = list(range(2, n+1)) primes = [] while True: primes.append(search[0]) for i,x in enumerate(search): if x % primes[-1] == 0: del search[i] if len(search) == 0 or search[0] >= math.sqrt(n): primes.extend(search) return primes for line in sys.stdin.readlines(): n = int(line) print(len(get_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 &le; <var>n</var> &le; 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>
s290815710
p00009
Runtime Error
import numpy def get_input(): while True: try: yield ''.join(input()) except EOFError: break def primesfrom3to(n): sieve = numpy.ones(int(n/2), dtype=numpy.bool) for i in range(3,int(n**0.5)+1,2): if sieve[int(i/2)]: sieve[int(i*i/2)::int(i)] = False return 2*numpy.nonzero(sieve)[0][1::]+1 if __name__ == "__main__": array = list(get_input()) for i in range(int(len(array))): primeList = list(primesfrom3to(int(array[i]))) primeList.insert(0,2) #print(primeList) print(len(primeList))
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 &le; <var>n</var> &le; 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>
s560162775
p00009
Runtime Error
import numpy def get_input(): while True: try: yield ''.join(input()) except EOFError: break def primesfrom3to(n): sieve = numpy.ones(int(n/2), dtype=numpy.bool) for i in range(3,int(n**0.5)+1,2): if sieve[int(i/2)]: sieve[int(i*i/2)::int(i)] = False return 2*numpy.nonzero(sieve)[0][1::]+1 if __name__ == "__main__": array = list(get_input()) for i in range(int(len(array))): primeList = list(primesfrom3to(int(array[i]))) primeList.insert(0,2) print(len(primeList))
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 &le; <var>n</var> &le; 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>
s826645863
p00009
Runtime Error
import numpy def get_input(): while True: try: yield ''.join(input()) except EOFError: break def primesfrom3to(n): sieve = numpy.ones(int(n/2), dtype=numpy.bool) for i in range(3,int(n**0.5)+1,2): if sieve[int(i/2)]: sieve[int(i*i/2)::int(i)] = False return 2*numpy.nonzero(sieve)[0][1::]+1 if __name__ == "__main__": array = list(get_input()) for i in range(int(len(array))): primeList = list(primesfrom3to(int(array[i]))) primeList.insert(0,2) #print(primeList) print(len(primeList))
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 &le; <var>n</var> &le; 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>
s206151166
p00009
Runtime Error
import numpy def get_input(): while True: try: yield ''.join(input()) except EOFError: break def primesfrom3to(n): #?????????n/2??????1byte??????data type = True or False??§??¨???1??§?????? sieve = numpy.ones(int(n/2), dtype=numpy.bool) if n%2 != 0: sieve = numpy.append(sieve,n/2) #i??????3??????2??????????????????n?????????????????§?????? for i in range(3,int(n**0.5)+1,2): #???????????¶=sieve???True or False??§??¨????????????????????¶??????????????????????´???°?????????????????¶?????\?????? if sieve[int(i/2)]: #????????°???False????????????int(i^2/2)?????????int(i)??????????????§False?????????????????? sieve[int(i*i/2)::int(i)] = False #??????????\???°?????? return 2*numpy.nonzero(sieve)[0][1::]+1 if __name__ == "__main__": array = list(get_input()) for i in range(int(len(array))): primeList = list(primesfrom3to(int(array[i]))) primeList.insert(0,2) #print(primeList) print(len(primeList))
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 &le; <var>n</var> &le; 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>
s174806111
p00009
Runtime Error
import numpy def get_input(): while True: try: yield ''.join(input()) except EOFError: break def primesfrom3to(n): sieve = numpy.ones(int(n/2), dtype=numpy.bool) if n%2 != 0: sieve = numpy.append(sieve,n/2) for i in range(3,int(n**0.5)+1,2): if sieve[int(i/2)]: sieve[int(i*i/2)::int(i)] = False return 2*numpy.nonzero(sieve)[0][1::]+1 if __name__ == "__main__": array = list(get_input()) for i in range(int(len(array))): primeList = list(primesfrom3to(int(array[i]))) primeList.insert(0,2) #print(primeList) print(len(primeList))
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 &le; <var>n</var> &le; 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>
s146023657
p00009
Runtime Error
import numpy def get_input(): while True: try: yield ''.join(input()) except EOFError: break def primesfrom3to(n): sieve = numpy.ones(int(n/2), dtype=numpy.bool) if n%2 != 0: sieve = numpy.append(sieve,n/2) for i in range(3,int(n**0.5)+1,2): if sieve[int(i/2)]: sieve[int(i*i/2)::int(i)] = False return 2*numpy.nonzero(sieve)[0][1::]+1 if __name__ == "__main__": array = list(get_input()) for i in range(int(len(array))): primeList = list(primesfrom3to(int(array[i]))) primeList.insert(0,2) #print(primeList) print(len(primeList))
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 &le; <var>n</var> &le; 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>
s069754059
p00009
Runtime Error
import sys prime = [0 for i in range(1000000)] isPrime = [1 for i in range(1000000)] isPrime[0] = 0 isPrime[1] = 0 p = 0 for i in sys.stdin: n = int(i) for i in range(2,n+1): if isPrime[i] == 1: p += 1 prime[p] = i for j in range(i*2, n+1, i): isPrime[j] = 0 print(sum(isPrime[:n+1]))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s867200623
p00009
Runtime Error
import random import sys def is_prime3(q,k=50): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False d = (q-1)>>1 while d&1 == 0: d >>= 1 for i in xrange(k): a = random.randint(1,q-1) t = d y = pow(a,t,q) while t != q-1 and y != 1 and y != q-1: y = pow(y,2,q) t <<= 1 if y != q-1 and t&1 == 0: return False return True a = [] for line in sys.stdin: a.append(line) nnum=[2] for i in a: num=int(i) if num==1: print "0" elif num==2: print "1" elif num==3: print "2" elif num<nnum[-1]: nnum.append(num) nnum.sort() time=nnum.index(num) nnum.remove(num) print time elif num==nnum[-1]: print len(nnum) else: add=len(nnum) time=0 if nnum[-1]==nnum[0]: d=1 else: d=nnum[-1] ch=(num-d)/2 for n in range(ch): n=n*2+d+2 if is_prime(n): time+=1 if n not in nnum: nnum.append(n) print time
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 &le; <var>n</var> &le; 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>
s294501893
p00009
Runtime Error
import math import sys lst=[0 for _ in xrange(999999)] def is_prime(num): if num%2==0: return 0 for x in range(3, int(num**0.5)+1,2): if num % x==0: return 0 return 1 lst[1]=0 lst[2]=1 for idx in range(3, len(lst)): lst[idx] = is_prime(idx) + lst[idx-1] for line in sys.stdin: print lst[int(line)]
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s510290430
p00009
Runtime Error
import math def isPrime(x): if x == 2: return True elif x < 2 or x % 2 == 0: return False else: i = 3 while i in range(math.sqrt(x)): if x % i == 0: return False i += 2 return True import sys dataset = sys.stdin.readlines() for n in dataset: n = int(n) counter = 0 for i in range(n+1): if isPrime(i): counter += 1 print(counter)
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 &le; <var>n</var> &le; 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>
s008466640
p00009
Runtime Error
import sys A = [] for i in sys.stdin: ary.append(int(i)) m = max(A) prime = [1] * (m + 1) prime[0] = 0 prime[1] = 0 for i in range(2, int(m ** 0.5) + 1): if prime[i] == 1: for j in range(i * 2, m + 1, i) prime[j] = 0 for i in range(len(A)): print(sum(prime[:A[i] + 1]))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>
s553676707
p00009
Runtime Error
import sys A = [] for i in sys.stdin: A.append(int(i)) m = max(A) prime = [1] * (m + 1) prime[0] = 0 prime[1] = 0 for i in range(2, int(m ** 0.5) + 1): if prime[i] == 1: for j in range(i * 2, m + 1, i) prime[j] = 0 for i in range(len(A)): print(sum(prime[:A[i] + 1]))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 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>