submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s784906927
p00009
Time Limit Exceeded
import sys def prime_calc(n): if n < 2: return 0 else: i = 2 while i*i <= n: if n % i == 0: return 0 else: i = i + 1 return 1 def prime(n): cnt = 0 for i in range(1, n+1): ans = prime_calc(i) if ans == 1: cnt = cnt + 1 return cnt def no_debug_input(array): for line in sys.stdin: array.append(int(line)) def debug_input(array): parser = argparse.ArgumentParser() parser.add_argument("filename", help="The filename to be processed") args = parser.parse_args() if args.filename: with open(args.filename) as f: for line in f: a = int(line.rstrip()) array.append(a) 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>
s381849919
p00009
Time Limit Exceeded
import sys def prime_calc(n): if n < 2: return 0 else: i = 2 while i*i <= n: if n % i == 0: return 0 else: i = i + 1 return 1 def prime(n): cnt = 0 for i in range(1, n+1): ans = prime_calc(i) if ans == 1: 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>
s736915607
p00009
Time Limit Exceeded
import sys def prime_calc(n): if n < 2: return False else: i = 2 while n > i: if n % i == 0: return False else: i += 1 return True def prime(n): cnt = 0 for i in range(0, 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>
s520835449
p00009
Time Limit Exceeded
import sys def prime_calc(n): if n < 2: return False else: i = 2 while n > i: if n % i == 0: return False else: i += 1 return True def prime(n): cnt = 0 for i in range(0, 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>
s206654543
p00009
Time Limit Exceeded
import sys def prime_calc(n): if n < 2: return False else: i = 2 while n > i: if n % i == 0: return False else: i += 1 return True def prime(n): cnt = 0 for i in range(0, n+1): ans = prime_calc(i) if ans is True: cnt = cnt + 1 return cnt def main(): a = [] for line in sys.stdin: a.append(int(line)) for line in a: 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>
s229738055
p00009
Time Limit Exceeded
while True: try: d = 0 a = int(input()) for c in range(2,a): for b in range(2,c): if c % b == 0: break else: d += 1 print d 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>
s584644418
p00009
Time Limit Exceeded
while True: t = [] try: a = int(input()) for n in range(2,a+1): for x in range(2,n): if n % x == 0: break else: t.append(n) print len(t[0:]) 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>
s967084866
p00009
Time Limit Exceeded
while True: t = [] b = 0 try: a = int(input()) for n in range(2,10000): for x in range(2,n): if n % x == 0: break else: t.append(n) for b in range(1000): if t[b] > a: print len(t[0:b]) break except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s304521897
p00009
Time Limit Exceeded
ans = [] while True: try: n = input() except EOFError: break l = range(3,n,2) for i in l: p = 2 while i*p in l: l.remove(i*p) p += 1 ans.append(len(l)) for i in ans: print 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>
s153364738
p00009
Time Limit Exceeded
import math import sys for s in sys.stdin: n = (int)(s) c = 1 f = True for i in range(3,n+1): for j in range(2,math.trunc(math.sqrt(i))+1): if i % j == 0: f = False if f: c += 1 f = True print c
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s320379122
p00009
Time Limit Exceeded
import math import sys for s in sys.stdin: n = (int)(s) if n == 0: break c = 1 f = True for i in range(3,n+1): for j in range(2,math.trunc(math.sqrt(i))+1): if i % j == 0: f = False if f: c += 1 f = True print c
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s348624959
p00009
Time Limit Exceeded
# -*- coding: utf-8 -*- while True: try: n = int(raw_input()) if n < 2: print(0) continue list1 = range(2, n + 1) list2 = [] while True: i = list1.pop(0) list2.append(i) for x in list1: if x % i == 0: list1.remove(x) if len(list1) == 0: break if i**2 > sorted(list1,lambda n1, n2:n2 - n1)[0]: break print(len(list2 + list1)) 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>
s358341159
p00009
Time Limit Exceeded
import sys for i in sys.stdin.readlines(): n=int(i) list = [p for p in range(2,n) if 0 not in [p%d for d in range(2,p)]] 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>
s605445728
p00009
Time Limit Exceeded
def GCM(m, n): r = m%n if r == 0: return n else: return GCM(n, r) while 1: try: n = input() c = 0 for i in range(2,n+1): for j in range(2,i): if GCM(i, j) != 1: break else: c += 1 print c except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s704464455
p00009
Time Limit Exceeded
import math def isPrime(n): if n == 2: return True if n%2 == 0: return False nMax = int(math.sqrt(n))+1 for i in range(3, nMax+1): if n%i == 0: return False else: return True while 1: try: n = input() c = 0 for i in range(2,n+1): if isPrime(i) is True: c += 1 print c except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s532482155
p00009
Time Limit Exceeded
import math def isPrime(n, primes): if n == 2: return True if n%2 == 0: return False nMax = int(math.sqrt(n))+1 for i in range(3, nMax+1): if n%i == 0: return False else: primes.append(n) return True while 1: try: n = input() c = 0 for i in range(2,n+1): p = [2] if isPrime(i, p) is True: c += 1 print c except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s434664236
p00009
Time Limit Exceeded
import math while 1: try: n = input() c = 0 ps = [False for i in range(n)] for i in range(2, n): ps[i] = True for i in range(2, int(math.sqrt(n)+1)): if ps[i]: for j in range(i**2, n, i): ps[j] = False for i in range(n): if ps[i] is True: c += 1 print c except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s960361164
p00009
Time Limit Exceeded
while 1: try: n = input() c = 0 ps = [False for i in range(n)] for i in range(2, n): ps[i] = True for i in range(2, int(n**0.5+1)): if ps[i]: for j in range(i**2, n, i): ps[j] = False for i in range(n): if ps[i] is True: c += 1 print c except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s711398326
p00009
Time Limit Exceeded
while 1: try: n = input() c = 0 ps = [False for i in range(n)] for i in xrange(2, n): ps[i] = True for i in xrange(2, int(n**0.5+1)): if ps[i]: for j in xrange(i**2, n, i): ps[j] = False for i in xrange(n): if ps[i] is True: c += 1 print c except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s076218087
p00009
Time Limit Exceeded
def prime(a): array = [] for i in range(2,a): if a % i == 0: array.append(1) if 1 in array: return 0 #not prime else: return 1 #prime while True: try: x = int(input()) sum = 0 for i in range(2,x+1): sum = sum + prime(i) print sum 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>
s848716384
p00009
Time Limit Exceeded
n = 1000000 search = [] for i in range(2,n): search.append(i) print primelist = [2] while True: for i in search: if i % primelist[-1] == 0: search.remove(i) if primelist[-1]**2 < search[-1]: primelist.append(search[0]) else: break primelist = primelist + search x = int(raw_input()) for i in range(len(primelist)): if x < primelist[i] : print i break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s517695635
p00009
Time Limit Exceeded
n = 1000000 search = [] for i in range(2,n): search.append(i) primelist = [2] while True: for i in search: if i % primelist[-1] == 0: search.remove(i) if primelist[-1]**2 < search[-1]: primelist.append(search[0]) else: break primelist = primelist + search print primelist while True: try: x = int(raw_input()) for i in range(len(primelist)): if x < primelist[i] : print i break except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s938437770
p00009
Time Limit Exceeded
n = 1000000 search = [] for i in range(3,n,2): search.append(i) primelist = [2,3] while True: for i in search: if i % primelist[-1] == 0: search.remove(i) if primelist[-1]**2 < search[-1]: primelist.append(search[0]) else: break primelist = primelist + search while True: try: x = int(raw_input()) for i in range(len(primelist)): if x < primelist[i] : print i break except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s668776377
p00009
Time Limit Exceeded
while True: try: n = int(raw_input()) except EOFError: break count = 0 for i in range(2, n + 1): for j in range(2, i): if i % j == 0: break else: 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>
s347679516
p00009
Time Limit Exceeded
while True: try: n = int(raw_input()) except EOFError: break sieve = map(lambda x:False, range(2, n + 1)) for i in range(2, n + 1): if sieve[i - 2]: continue for j in range(i * 2, n + 1, i): sieve[j - 2] = True print sieve.count(False)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s567690714
p00009
Time Limit Exceeded
def sieve(n): a = [1 for i in range(n + 1)] for i in range(2, n + 1): if a[i]: for j in range(2 * i, n + 1, i): a[j] = 0 return a[2:] while True: try: n = int(raw_input()) print len(filter(lambda x: x, sieve(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>
s551482840
p00009
Time Limit Exceeded
from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin def enum_prime(n): if n < 2: return [] if n == 2: return [2] L = list(range(2, n + 1)) PL = [] while True: PL.append(L[0]) L = [i for i in L if i % PL[-1] != 0] if L[-1] < PL[-1] ** 2: return PL + L for line in stdin: print(len(enum_prime(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>
s128666706
p00009
Time Limit Exceeded
while True: try: integer = [x for x in range(1,input()+1)] del integer[0] print integer primes = [] while len(integer) != 0: primes.append(integer[0]) for val in integer: if val == integer[0]: pass else: if val % integer[0] == 0: integer.remove(val) else: pass del integer[0] print len(primes) 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>
s432531942
p00009
Time Limit Exceeded
while True: try: integer = [x for x in xrange(1,input()+1)] del integer[0] print integer primes = [] while len(integer) != 0: primes.append(integer[0]) for val in integer: if val == integer[0]: pass else: if val % integer[0] == 0: integer.remove(val) else: pass del integer[0] print len(primes) 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>
s807015343
p00009
Time Limit Exceeded
while True: try: integer = [x for x in xrange(1,input()+1)] del integer[0] primes = [] while len(integer) != 0: primes.append(integer[0]) for val in integer: if val == integer[0]: pass else: if val % integer[0] == 0: integer.remove(val) else: pass del integer[0] print len(primes) 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>
s804152197
p00009
Time Limit Exceeded
while True: try: integer = [x for x in xrange(1,input()+1)] del integer[0] primes = [] while len(integer) != 0: primes.append(integer[0]) for val in xrange(2,integer[-1]/integer[0]+1): if integer[0]*val in integer: integer.remove(integer[0]*val) del integer[0] print len(primes) 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>
s624446910
p00009
Time Limit Exceeded
import sys def prime_list(n): limit = int(n ** 0.5) + 1 lis = range(1, n + 1, 2) lis[0] = 2 while True: if len(lis) == 0: break p = lis.pop(0) yield p if p <= limit: lis = [x for x in lis if x % p != 0] def primes_number(n): primes = [] for p in prime_list(n): primes.append(p) return len(primes) #input_file = open(sys.argv[1], "r") #for line in input_file: for line in sys.stdin: n = int(line) print primes_number(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>
s115021872
p00009
Time Limit Exceeded
# -*- coding: utf-8 -*- import sys if __name__ == "__main__": st = 2 for line in sys.stdin: num_list = [] prime_list = [] counter = 1 # initialize val while (counter < int(line)): counter += 1 num_list.append(counter) prime_list.append(0) # process while ((len(num_list) != 0) and (max(num_list) > max(prime_list))): prime_list.append(num_list[0]) num = num_list[0] c = 1 while ((c*num) <= int(line)): if (c*num) in num_list: num_list.remove(c*num) c += 1 if 0 in prime_list: prime_list.remove(0) print str(len(prime_list))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s728807312
p00009
Time Limit Exceeded
while True: try: n = input() print len([i for i in range(2,n+1) if 0 not in [i%j for j in range(2,i)]]) 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>
s159793578
p00009
Time Limit Exceeded
while True: try: n,m = range(2, input()+1),2 for i in n: j = 0 while j < len(n): if ((n[j]%m == 0) and (n[j] != m)): del n[j] j += 1 m += 1 print 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>
s953367296
p00009
Time Limit Exceeded
import sys def ifPrime(n): for i in range(2,n): if n % i == 0: return False return True def solve(): while True: N = int(raw_input()) #print N c = 0 for i in range(2,N + 1): if ifPrime(i) is True: c += 1 print c if __name__ == "__main__": solve()
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s809965792
p00009
Time Limit Exceeded
import sys nyu = sys.stdin.readlines() nyu = map(int,nyu) syu = "" for a in nyu: ps = [] for i in xrange(2,a+1): isp = True for j in ps: if i%j==0: isp = False break if isp: ps.append(i) syu += str(len(ps)) +"\n" print syu
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s108879709
p00009
Time Limit Exceeded
import sys for line in sys.stdin: a = int(line) ps = [] for i in xrange(2,a+1): isp = True for j in ps: if i%j==0: isp = False break if isp: ps.append(i) print str(len(ps))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s680982511
p00009
Time Limit Exceeded
# Prime Number import sys def count_prime_numer(n): if n <= 1: return 0 elif n == 2: return 1 else: count = 1 for prime in xrange(3, n + 1, 2): for i in xrange(3, prime - 1): if prime % i == 0: break else: count += 1 return count datas = [] for line in sys.stdin: datas.append(int(line)) for data in datas: print count_prime_numer(data)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s695472419
p00009
Time Limit Exceeded
# Prime Number import sys import math primes = [2] for prime in xrange(3, 1000000, 2): for i in xrange(3, int(math.sqrt(prime)) + 1): if prime % i == 0: break else: primes.append(prime) datas = [] for line in sys.stdin: datas.append(int(line)) for data in datas: count = 0 for prime in primes: if prime <= data: count += 1 else: break 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>
s438345254
p00009
Time Limit Exceeded
# Prime Number import sys count = 0 primes = [2, 3] for n in xrange(5, 1000001, 2): isprime = True for i in xrange(1, len(primes)): count += 1 if primes[i] * primes[i] > n: break count += 1 if n % primes[i] == 0: isprime = False break if isprime: primes.append(n) datas = [] for line in sys.stdin: datas.append(int(line)) for data in datas: count = 0 for prime in primes: if prime <= data: count += 1 else: break 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>
s495021785
p00009
Time Limit Exceeded
import sys for line in sys.stdin: n = int(line.rstrip('\n')) primeNumbers = range(1, n+1) for i in range(2, n+1): if primeNumbers[i-1] > 0: j = 2 * i while j <= n: primeNumbers[j-1] = 0 j += i print sum(1 for primeNumber in primeNumbers if primeNumber > 0) - 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>
s327551318
p00009
Time Limit Exceeded
import sys def isPrimeNumber(candidate): divisor = 2 while divisor < candidate: if candidate % divisor == 0: return False else: divisor += 1 return True for line in sys.stdin: primeNumberCount = 0 n = int(line.rstrip('\n')) candidate = 2 while candidate <= n: if isPrimeNumber(candidate): primeNumberCount += 1 candidate += 1 print primeNumberCount
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s053256301
p00009
Time Limit Exceeded
import sys import math def isPrimeNumber(candidate): divisor = 2 while divisor <= math.sqrt(candidate): if candidate % divisor == 0: return False else: divisor += 1 return True for line in sys.stdin: primeNumberCount = 0 n = int(line.rstrip('\n')) candidate = 2 while candidate <= n: if isPrimeNumber(candidate): primeNumberCount += 1 candidate += 1 print primeNumberCount
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s741975454
p00009
Time Limit Exceeded
import sys for line in sys.stdin: count = 0 n = int(line) nums = range(2, n+1) while True: if len(nums) == 0: break elif len(nums) == 1: count += 1 break else: count += 1 m = nums[0] numsCandidate = nums[1:] nums = [ x for x in numsCandidate if x % m != 0 ] 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>
s293834738
p00009
Time Limit Exceeded
while 1: try: n, p = input(), 0 except EOFError: break for x in range(1,n+1,2): for y in range(3,x/2,2): print x, y, x % y if x % y == 0: break else: p += 1 print p
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s153406170
p00009
Time Limit Exceeded
while 1: try: n, p = input(), 0 except EOFError: break for x in xrange(1,n+1,2): for y in xrange(3,int(x**0.5)+1,2): if x % y == 0: break else: p += 1 print p
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s454924984
p00009
Time Limit Exceeded
import math import sys for line in sys.stdin: n = int(line) nums = [1] * (n+1) nums[:2] = [0,0] cnt = 0 while cnt <= math.sqrt(n): flg = nums[cnt] if flg == 1: k = 2 while k*cnt <= n: nums[k*cnt] = 0 k += 1 cnt += 1 print sum(nums)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s956189630
p00009
Time Limit Exceeded
import sys def isPrime(num): flag = True for i in range(2, num): if num % i == 0: flag = False break return flag def countPrime(num): count = 0 for i in range(2, num+1): if isPrime(i): count += 1 return count if __name__ == '__main__': nums = [] for num in sys.stdin: nums.append(int(num)) for num in nums: print countPrime(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>
s810279913
p00009
Time Limit Exceeded
import sys,random rand = random.randint def prime(n): if n == 2: return True if n == 1 or n & 1 == 0: return False d = n-1 while d & 1 == 0: d >>= 1 for i in range(20): a = rand(1,n-1) t = d y = pow(a, t, n) while t != n-1 and y != 1 and y != n-1: y = pow(y,2,n) t <<= 1 if y != n-1 and t & 1 == 0: return False return True a = [prime(i) for i in range(1000000)] for s in sys.stdin: i = int(s) print(a[:i+1].count(True))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s805336803
p00009
Time Limit Exceeded
import sys,math def prime(m): N=range(1,m+2,2) r=int(m**.5) h=len(N) N[0]=0 for i in range(h): x=N[i] if x>r:break if x and i+x<h:N[i+x:h:x]=[0]*((h-1-i-x)/x+1) N[0]=2 return filter(None,N) A=map(int,sys.stdin) n=max(A)+1 B=[0]*n for e in prime(n): for i in range(e,n):B[i]+=1 for e in A:print B[e]
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s027410397
p00009
Time Limit Exceeded
import sys for line in sys.stdin: n = int(line) l = range(2,n+1) i = 2 while i * i <= n: l = filter(lambda x: x == i or x % i != 0, l) i = i + 1 print len(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>
s764434541
p00009
Time Limit Exceeded
import sys def prime_list(n): l = range(2,n+1) i = 2 while i * i <= n: l = filter(lambda x: x == i or x % i != 0, l) i = i + 1 return l if __name__ == '__main__': l = prime_list(999999) for line in sys.stdin: n = int(line) print len([x for x in l if x <= n])
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s089005204
p00009
Time Limit Exceeded
# -*- coding: utf-8 -*- import sys def isprime(n): for i in xrange(2, int(n**0.5)+1): if n % i == 0: return False return True #for line in ["35"]: for line in sys.stdin.readlines(): List = map(int, line.strip().split()) n = List[0] ans = 0 for i in xrange(2, n+1): if isprime(i): ans += 1 print ans
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s068680417
p00009
Time Limit Exceeded
# -*- coding: utf-8 -*- import sys def isprime(n): for i in xrange(2, int(n**0.5)+1): if n % i == 0: return False return True limit = 1000000 ansList = [0] # 1 is not prime cnt = 0 for i in xrange(2, limit): if isprime(i): cnt += 1 ansList.append(cnt) #for line in ["999999"]: for line in sys.stdin.readlines(): List = map(int, line.strip().split()) n = List[0] print ansList[n-1]
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s723311173
p00009
Time Limit Exceeded
# -*- coding: utf-8 -*- import sys def isprime(n): for i in xrange(2, int(n**0.5)+1): if n % i == 0: return False return True limit = 1000000 ansList = [0]*limit # 1 is not prime cnt = 0 for i in xrange(2, limit): if isprime(i): cnt += 1 ansList[i-1] = cnt for line in ["999999"]: #for line in sys.stdin.readlines(): List = map(int, line.strip().split()) n = List[0] print ansList[n-1]
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s719203325
p00009
Time Limit Exceeded
# -*- coding: utf-8 -*- import sys def isprime(n): for i in xrange(2, int(n**0.5)+1): if n % i == 0: return False return True limit = 1000000 ansList = [0]*limit # 1 is not prime cnt = 0 for i in xrange(2, limit): if isprime(i): cnt += 1 ansList[i-1] = cnt #for line in ["999999"]: for line in sys.stdin.readlines(): List = map(int, line.strip().split()) n = List[0] print ansList[n-1]
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s028258807
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) if n < 2: ans.append(0) continue prime_list = range(2, n + 1) head = prime_list[0] i = 0 while head < math.sqrt(n): for j in range(len(prime_list) - 1, 0, -1): if (prime_list[j] % head == 0) & (prime_list[j] != head): del prime_list[j] i += 1 head = prime_list[i] ans.append(len(prime_list)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s068273252
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) if n < 2: ans.append(0) continue prime_list = range(3, n + 1, 2) prime_list.insert(0, 2) head = prime_list[0] i = 0 while head < math.sqrt(n): for j in range(len(prime_list) - 1, 0, -1): if (prime_list[j] % head == 0) & (prime_list[j] != head): del prime_list[j] i += 1 head = prime_list[i] ans.append(len(prime_list)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s151173805
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) isPrime = [False, False] for i in range(n - 1): isPrime.append(True) i = 2 while i < math.sqrt(n): j = i * 2 while j < len(isPrime): isPrime[j] = False j += i i += 1 ans.append(isPrime.count(True)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s776509563
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) isPrime = [False, False] for i in range(n - 1): isPrime.append(-1) i = 2 while i < math.sqrt(n): j = i while j < len(isPrime): isPrime[j] = False j += i isPrime[i] = True i = isPrime.index(-1) ans.append(isPrime.count(True) + isPrime.count(-1)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s176275468
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) isPrime = [-1] * (n + 1) isPrime[0], isPrime[1] = False, False i = 2 while i * i < n: j = i while j < len(isPrime): isPrime[j] = False j += i isPrime[i] = True i = isPrime.index(-1) ans.append(isPrime.count(True) + isPrime.count(-1)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s633560765
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) isPrime = [-1] * (n + 1) isPrime[0], isPrime[1] = False, False #isPrime[2] = True i = 2 while i * i < n: for j in range(i, n+1, i): isPrime[j] = False isPrime[i] = True i = isPrime.index(-1) print isPrime ans.append(isPrime.count(True) + isPrime.count(-1)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s082890515
p00009
Time Limit Exceeded
import math ans = [] while True: try: n = int(raw_input()) isPrime = [-1] * (n + 1) isPrime[0], isPrime[1] = False, False i = 2 while i * i <= n: j = 2 while j * i <= n: #for j in range(i, n+1 ,i): #print "%d,"%(j), isPrime[j * i] = False j += 1 isPrime[i] = True i = isPrime.index(-1) ans.append(isPrime.count(True) + isPrime.count(-1)) except EOFError: break for num in ans: print num
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s406459006
p00009
Time Limit Exceeded
while True: try: n = int(raw_input()) filter = [1 for i in range(n)] filter[0] = 0 for i in range(2,n//2): j = 2 k = i*j while k < n: filter[k-1] = 0 j += 1 k = i*j print filter sum = 0 for i in filter: sum += i print sum 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>
s862112023
p00009
Time Limit Exceeded
while True: try: n = int(raw_input()) filter = [1 for i in range(n)] filter[0] = 0 for i in range(2,n//2): if filter[i] == 1: j = 2 k = i*j while k < n: filter[k-1] = 0 j += 1 k = i*j print filter sum = 0 for i in filter: sum += i print sum 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>
s822040212
p00009
Time Limit Exceeded
import math while True: try: n = int(raw_input()) prime=[] if n == 1: print 0 elif n == 2: print 1 else: for i in range(3, n+1, 2): isprime = 1 sqrt = int(math.sqrt(i)) for j in prime: if i % j == 0: isprime = 0 break if j > sqrt: break if isprime: prime.append(i) print len(prime)+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>
s367411202
p00009
Time Limit Exceeded
import math r = 999999 sqrt = int(math.sqrt(r)) p = [1 for i in range(r)] p[0] = 0 for i in p: if i: for j in range(2*(i+1)-1,r,i+1): p[j] = 0 while True: try: n = int(raw_input()) print sum(p[:n]) except: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s011153155
p00009
Time Limit Exceeded
import math r = 999999 sqrt = int(math.sqrt(r)) p = [1 for i in range(r)] p[0] = 0 for i in p[:sqrt]: if i: for j in range(2*(i+1)-1,r,i+1): p[j] = 0 while True: try: n = int(raw_input()) print sum(p[:n]) except: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s999304012
p00009
Time Limit Exceeded
import sys for n in sys.stdin: num = int(n) ifprime = [1]*(num+1) ifprime[0] = ifprime[1] = 0 a = 2 while a*a <= num: if ifprime[a]: b = a*a while b <= num: ifprime[b] = 0 b += a a += 1 print sum(ifprime)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s524548993
p00009
Time Limit Exceeded
import math while True: num = int(raw_input()) tmp = [i+1 for i in range(1, num)] x = math.sqrt(num) for i in tmp: if i > x: break for j in range(2,num): if i*j > num: break if i*j in tmp: tmp.remove(i*j) print len(tmp)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s237477470
p00009
Time Limit Exceeded
def isPrime(p): if p == 2: return 1 if p < 2 or p&1 == 0: return 0 return 1 if pow(2,p-1,p) == 1 else 0 while True: try: n = int(raw_input()) print sum(isPrime(i) for i in range(1,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>
s620367997
p00009
Time Limit Exceeded
def isPrime(p): if p == 2: return 1 if p < 2 or p&1 == 0: return 0 return 1 if pow(2,p-1,p) == 1 else 0 while True: try: n = int(raw_input()) print sum(isPrime(i) for i in range(3,n+1,2))+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>
s948677943
p00009
Time Limit Exceeded
def isPrime(p): if p == 2: return 1 if p < 2 or p&1 == 0: return 0 return 1 if pow(2,p-1,p) == 1 else 0 while True: try: n = int(raw_input()) print sum(isPrime(i) for i in range(5,n+1,2))+2 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>
s519524072
p00009
Time Limit Exceeded
import sys def isPrime(n): prime = True for i in range(2, n): if n % i == 0: prime = False break return prime def countPrime(n): count = 0 for i in range(2, n + 1): if isPrime(i): count += 1 return count for line in sys.stdin: n = int(line) print countPrime(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>
s079287433
p00009
Time Limit Exceeded
def sieve(n): nums = [i+1 for i in range(2, n, 2)] ans = [2] while len(nums) != 0: for i in range(nums[0]*2, nums[-1]+1, nums[0]): if i in nums: nums.remove(i) ans.append(nums.pop(0)) return len(ans) while True: try: print sieve(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>
s588356032
p00009
Time Limit Exceeded
#!/usr/bin/python def judge_prime(n): if n == 2: return True if n < 2: return False return pow(2, n-1, n) == 1 while True: try: ans = 0 for i in range(input()): if judge_prime(i+1): ans += 1 print ans except: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s001856025
p00009
Time Limit Exceeded
#!/usr/bin/env python # -*- coding:utf-8 -*- import sys for n in sys.stdin: prime=[] n=int(n) for i in range(2,n+1): if all(i%p!=0 for p in prime): prime+=[i] print len(prime)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s203742980
p00009
Time Limit Exceeded
def sieve(n): a = range(n) a[0], a[1] = None, None for i in range(2, n): if i ** 2 >= n: break if a[i] is None: continue for j in range(i ** 2, n, i): a[j] = None j = 0 for i in range(n): if a[i] is not None: a[j] = a[i] j += 1 return a[0:j] try: while True: print len(sieve(int(raw_input()) + 1)) except: pass
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s992895996
p00009
Time Limit Exceeded
import math def get_primes(goal): n_list = range(3,goal+1,2) primes = [2] sieve = map(lambda n:[n,1],n_list)#Sieve of Eratosthenes while sieve[0][0] < math.sqrt(goal+1): target = sieve[0][0] primes = primes + [target] i = 0 while i < len(sieve): sieve[i][1] = 0 i += target while sieve[0][1] == 0: sieve = sieve[1:] primes = primes + map(lambda x:x[0],filter(lambda n:n[1] ,sieve)) return primes def bin_search_count(list,cond): if cond(list[0]) and cond(list[-1]): return len(list) if cond(list[0]) == False and cond(list[-1]) == False: return 0 Imin = 0 Imax = len(list) - 1 Imid = int(Imin * 0.5 + Imax * 0.5) return bin_search_count(list[:Imid + 1],cond) + bin_search_count(list[Imid + 1:],cond) primes = get_primes(1000000) while 2>1: try: n = int(raw_input()) print bin_search_count(primes,lambda x:x <= n) except EOFError: break except ValueError: 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>
s334207511
p00009
Time Limit Exceeded
import math def bin_search_count(list,cond): if cond(list[0]) and cond(list[-1]): return len(list) if cond(list[0]) == False and cond(list[-1]) == False: return 0 Imin = 0 Imax = len(list) - 1 Imid = int(Imin * 0.5 + Imax * 0.5) return bin_search_count(list[:Imid + 1],cond) + bin_search_count(list[Imid + 1:],cond) def get_primes(goal): primes = [2,3] prime_index = 1 goalrt = math.sqrt(goal+1) sieve = map(lambda n:[n,1],range(5,goal+1,2))#Sieve of Eratosthenes while primes[prime_index] < goalrt: target = primes[prime_index] targetsq = target ** 2 part_index = bin_search_count(sieve,lambda n: n[0] < targetsq) primes = primes + map(lambda nd:nd[0],filter(lambda n: n[1] == 1 , sieve[:part_index])) sieve = sieve[part_index:] i = 0 while i < len(sieve): sieve[i][1] = 0 i += target prime_index += 1 primes = primes + map(lambda nd:nd[0],filter(lambda n:n[1] ,sieve)) return primes primes = get_primes(1000000) while 2>1: try: n = int(raw_input()) print bin_search_count(primes,lambda x:x <= n) except EOFError: break except ValueError: 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>
s595183259
p00009
Time Limit Exceeded
while 1: number = int(raw_input()) result = [] for i in range(2,number+1): for j in range(2,i+1): if i == j: result.append(i) elif i % j == 0: break print len(result)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s281183693
p00009
Time Limit Exceeded
while 1: number = int(raw_input()) result = [] for i in range(2,number+1): for j in range(2,i+1): if i == j: result.append(i) elif i % j == 0: break print len(result)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s005545652
p00009
Time Limit Exceeded
while True: try: n = int(raw_input()) era=[True]*(n) for i in xrange(2,n): if(era[i-1]): for j in xrange(i*i-1,n,i): era[j]=False print era[1:n].count(True) except EOFError: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s112091455
p00009
Time Limit Exceeded
def isprime(n): p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True while True: try: n = int(input()) except: break count = int(n >= 2) for p in range(3,n + 1,2): if isprime(p): 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>
s442097114
p00009
Time Limit Exceeded
# coding: utf-8 import math def sieve_of_erastosthenes(num): if 2 > num: return 0 serial_number_list = [r for r in range(2, num + 1)] multiple_list = [] while math.sqrt(num) >= serial_number_list[0]: i = 1 serial_number = serial_number_list[0] multiple_list.append(serial_number) while serial_number_list[len(serial_number_list) - 1] >= serial_number * i: if serial_number * i in serial_number_list: serial_number_list.pop(serial_number_list.index(serial_number * i)) i += 1 return len(multiple_list + serial_number_list) if __name__ == '__main__': input_list = [] while True: try: print(sieve_of_erastosthenes(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>
s026908475
p00009
Time Limit Exceeded
import math def sieve_of_erastosthenes(num): input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)] input_list[0] = input_list[1] = False input_list[2] = input_list[3] = input_list[5] = True sqrt = math.sqrt(num) for serial in range(3, num, 2): if serial >= sqrt: return input_list for s in range(serial ** 2, num, serial): input_list[s] = False if __name__ == '__main__': while True: try: n = int(input()) except: break if 5 >= n: print(1) else: input_list = sieve_of_erastosthenes(n) print(sum(input_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>
s956095694
p00009
Memory Limit Exceeded
import sys l = [2] for i in range(3,999999): for j in l: if i % j == 0: break else: l.append(i) for line in sys.stdin.readlines(): count = 0 n = int(line.rstrip()) for i in n: if i in l: 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>
s620720319
p00009
Memory Limit Exceeded
import sys LIMIT = 10000000 isPrime = [True] * LIMIT isPrime[0] = isPrime[1] = False for i in range(2, int(LIMIT ** 0.5)+1): print(i) if isPrime[i]: for j in range(2 * i, LIMIT, i): isPrime[j] = False countPrime = [0] * LIMIT for i in range(1, LIMIT): countPrime[i] = countPrime[i-1] + isPrime[i] for line in sys.stdin.readlines(): print(countPrime[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>
s293203968
p00009
Memory Limit Exceeded
LIMIT = 10000000 isPrime = [True for _ in range(LIMIT)] isPrime[0] = isPrime[1] = False for i in range(2, int(LIMIT ** 0.5)+1): if isPrime[i]: for j in range(2 * i, LIMIT, i): isPrime[j] = False countPrime = [0 for _ in range(LIMIT)] for i in range(1, LIMIT): countPrime[i] = countPrime[i-1] + isPrime[i] try: while True: n = int(input()) print(countPrime[n]) except EOFError: pass
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s373677777
p00009
Accepted
import sys, math class Eratos(object): def __init__(self, N): self.N = N self._primes = {i:True for i in range(2, N+1)} def filter(self): end = self.N if self.N > 5: end = math.ceil(self.N**0.5) + 1 for n in range(2, end): if not self._primes[n]: continue for x in range(n*2, self.N+1, n): if x in self._primes: self._primes[x] = False def primes(self, x): return [k for k,v in self._primes.items() if v == True and k <= x] def run(): e = Eratos(999999) e.filter() for _n in sys.stdin: N = int(_n) print(len(e.primes(N))) if __name__ == '__main__': run()
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s280481647
p00009
Accepted
import sys from math import floor, sqrt from bisect import bisect_right primes = [2] def isPrime(v): threshold = floor(sqrt(v)) for p in primes: if p > threshold: break if v % p == 0: return False return True for v in range(3, 1000000, 2): if isPrime(v): primes.append(v) values = [] for line in sys.stdin: values.append(int(line)) for v in values: print(bisect_right(primes, v))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s328242851
p00009
Accepted
prime=[2] for i in range(3,1000000,2): primeq=True for p in prime: if i%p==0: primeq=False break if i<p*p:break if primeq:prime.append(i) while True: try: n=int(input()) ans=0 for p in prime: if p>n:break ans+=1 print(ans) except:break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s895441254
p00009
Accepted
from sys import stdin a = [True]*1000000 for i in range(2,1000000): if a[i]: for j in range(i+i, 1000000)[::i]: a[j] = False b = [None]*1000000 b[0] = b[1] = 0 for i in range(2,1000000): if a[i]: b[i] = b[i-1] + 1 else: b[i] = b[i-1] while True: try: print(b[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>
s567257685
p00009
Accepted
numlist=[0,0,1]+[0]*999998 for i in range(3,1000000,2): numlist[i]=1 for i in range(3,1000,2): if numlist[i]==1: for j in range(i*i,1000000,i): numlist[j]=0 cnt=[0,0,1]+[0]*999999 count=1 for i in range(3,1000000,2): if numlist[i]: count+=1 cnt[i]=cnt[i+1]=count while True: try: n=int(input()) print(cnt[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>
s341155361
p00009
Accepted
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>
s281359767
p00009
Accepted
# AOJ 0009 import sys ps = [0]*10**6 used = [False]*10**6 p = 0 def sieve(): global p used[0] = used[1] = True for i in xrange(0,10**6): if not used[i]: ps[p] = i p+=1 for j in xrange(i,10**6,i): used[j] = True def upper_bound(x): lb = -1 ub = p while ub-lb > 1: mid = lb+ub>>1 if ps[mid] > x: ub = mid else: lb = mid return ub sieve() for i in sys.stdin: print upper_bound(int(i))
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>
s975088234
p00009
Accepted
#! -*- coding: utf-8-unix -*- #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0004 import sys M=[True] * 1000000 M[0] = M[1] = False for i in xrange(2, len(M)): # print i if M[i]: j = i + i while j < len(M): M[j] = False j += i def main(lines): d = {} for line in lines: d[int(line)] = 0 count = 0 for i in range(len(M)): if M[i]: count += 1 if d.has_key(i): d[i] = count for line in lines: print d[int(line)] if __name__=='__main__': lines = [x.strip() for x in sys.stdin.readlines()] for line in sys.stdin: lines.append(line.strip()) # print lines main(lines)
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 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>
s659054472
p00009
Accepted
if __name__ == "__main__": maxn = 1000000 plist = [False if i%2==0 or i%3==0 or i%5==0 else True for i in range(maxn)] plist[0] = plist[1] = False plist[2] = plist[3] = plist[5] = True for chki in range(3, maxn, 2): for j in range(chki**2, maxn, chki): plist[j] = False while True: try: #start = time.time() inn = int(raw_input()) print plist[0:inn+1].count(True) #print plist #print plist.count(True) #print plist[0:10].count(True) #print plist[0:100000].count(True) #print plist[0:1000000].count(True) #elapsedTime = time.time() -start #print elapsedTime 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>
s105952797
p00009
Accepted
isPrime = [True] * 1000000 prime = [0, 0] def calcPrime(): isPrime[0] = isPrime[1] = False count = 0 for i in range(2, len(isPrime)): if(isPrime[i]): count += 1 prime.append(count) for j in range(2 * i, len(isPrime), i): isPrime[j] = False else: prime.append(count) calcPrime() while(True): try: n = input() print(prime[n]) except Exception: break
10 3 11
4 2 5
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &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>