summaryrefslogtreecommitdiff
path: root/python/lswf.py
blob: 89230ea87b404d3b10bc3218f35cbc2d2998cef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fib = []
fib.append(1)
fib.append(1)

def fibonacci(N):
    for i in range(2, N):
        fib.append(fib[i - 1] + fib[i - 2])

        if fib[i] > N:
            break
    return i


with open('input.txt', 'r') as fin:
    N = int(fin.readline())

fibonacci(N)

fib.reverse()
print()

somma = 0
seq = []
for i in range(0,len(fib)-1):
    potSomma = somma + fib[i]
    if potSomma < N:
        somma = potSomma
        seq.append(1)
    else:
        seq.append(0)

seq.append(1)
seq.reverse()

if N == 1 or N > 4:
    seq.pop()

with open('output.txt', 'w') as fout:
    for i in seq:
        fout.write(str(i))