48 lines
782 B
Python
48 lines
782 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import sys
|
||
|
import math
|
||
|
|
||
|
def digits(A, n):
|
||
|
if n == 0:
|
||
|
A[0] = True
|
||
|
return
|
||
|
|
||
|
while n != 0:
|
||
|
A[n % 10] = True
|
||
|
n = n // 10
|
||
|
|
||
|
|
||
|
def check(A):
|
||
|
n = 0
|
||
|
for i in range(10):
|
||
|
if A[i]:
|
||
|
n = n + 1
|
||
|
return n == 10
|
||
|
|
||
|
|
||
|
def count_sheep(start):
|
||
|
if start == 0:
|
||
|
return "INSOMNIA"
|
||
|
|
||
|
A = [False,False,False,False,False,False,False,False,False,False]
|
||
|
|
||
|
n = start
|
||
|
while True:
|
||
|
digits(A, n)
|
||
|
if check(A):
|
||
|
return str(n)
|
||
|
n += start
|
||
|
|
||
|
return "INSOMNIA"
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
i = 0
|
||
|
for line in sys.stdin:
|
||
|
if i == 0:
|
||
|
i = i + 1
|
||
|
continue
|
||
|
print('Case #' + str(i) + ": " + count_sheep(int(line)))
|
||
|
i = i + 1
|