BASE = 2 with open('cyclic_result.txt', 'w') as f: def to_binary(a, b): temp = a chk = [a] ret = '' while True: temp *= BASE if temp > b: temp -= b ret += '1' elif temp == b: ret += '1' return (0, '.' + ret) else: ret += '0' chk.append(temp) if (len(chk) - len(set(chk))) != 0: for i in range(len(chk) - 1): if chk[i] == chk[-1]: ret = ret[:i] + 'r' + ret[i:] break return len(ret[ret.index('r'):]) - 1, '.' + ret nu = int(input('λΆ„μž: ')) end = int(input('끝: ')) for i in range(nu + 1, end): if to_binary(nu, i)[0] == i - 1: f.write(str(i) + ', ')