1#! /usr/bin/env python
2
3# Print prime numbers in a given range
4
5def primes(min, max):
6    if max >= 2 >= min:
7        print 2
8    primes = [2]
9    i = 3
10    while i <= max:
11        for p in primes:
12            if i % p == 0 or p*p > i:
13                break
14        if i % p != 0:
15            primes.append(i)
16            if i >= min:
17                print i
18        i += 2
19
20def main():
21    import sys
22    min, max = 2, 0x7fffffff
23    if sys.argv[1:]:
24        min = int(sys.argv[1])
25        if sys.argv[2:]:
26            max = int(sys.argv[2])
27    primes(min, max)
28
29if __name__ == "__main__":
30    main()
31