Created
August 29, 2014 14:55
-
-
Save kg86/0f53dccc4694cd7374ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment