Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Created August 11, 2012 06:47
Show Gist options
  • Save tos-kamiya/3321881 to your computer and use it in GitHub Desktop.
Save tos-kamiya/3321881 to your computer and use it in GitHub Desktop.
Jojo problem
# 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