Created
August 11, 2012 06:47
-
-
Save tos-kamiya/3321881 to your computer and use it in GitHub Desktop.
Jojo problem
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
# coding: utf-8 | |
import sys | |
# For each integer 1..n, print "jojo" if it is a prime number, | |
# else print the number. | |
def jojo_iter(num): | |
if 1 <= num: | |
yield 1 | |
sieve = [True] * (num + 1) | |
for i in range(2, num + 1): | |
yield "jojo" if sieve[i] else i | |
for j in range(i, num + 1, i): | |
sieve[j] = False | |
def main(): | |
num = int(sys.argv[1]) | |
for v in jojo_iter(num): | |
print(v) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment