LINUX.ORG.RU

История изменений

Исправление Adonai, (текущая версия) :

Решение на Питоне (спасибо за подсказку про Пизано)

import sys

lineIn = sys.stdin.readline().split(" ")
n = int(lineIn[0])
m = int(lineIn[1])

fibPrev = 0
fib = 1
cached = [fibPrev, fib]

for curr in range(1, n):
    fibOld = fib
    fib = (fib + fibPrev) % m
    fibPrev = fibOld

    if fibPrev == 0 and fib == 1:
        cached.pop()
        break
    else:
        cached.append(fib)

offset = n % len(cached)
sys.stdout.write(str(cached[offset]))
python ~/Work/python/learning/fibonacci.py
1000000000001 99999
63715
Process finished with exit code 0
python ~/Work/python/learning/fibonacci.py
100000000000000000000000000001 100
1
Process finished with exit code 0

P.S. привет, господа из CompScience Center.

Исправление Adonai, :

Решение на Питоне (спасибо за подсказку про Пизано)

import sys

lineIn = sys.stdin.readline().split(" ")
n = int(lineIn[0])
m = int(lineIn[1])

fibPrev = 0
fib = 1
cached = [fibPrev, fib]

for curr in range(1, n):
    fibOld = fib
    fib = (fib + fibPrev) % m
    fibPrev = fibOld

    if fibPrev == 0 and fib == 1:
        cached.pop()
        break
    else:
        cached.append(fib)

offset = n % len(cached)
sys.stdout.write(str(cached[offset]))
python ~/Work/python/learning/fibonacci.py
1000000000001 99999
63715
Process finished with exit code 0
python ~/Work/python/learning/fibonacci.py
100000000000000000000000000001 100
1
Process finished with exit code 0

Исправление Adonai, :

Решение на Питоне (спасибо за подсказку про Пизано)

import sys

lineIn = sys.stdin.readline().split(" ")
n = int(lineIn[0])
m = int(lineIn[1])

fibPrev = 0
fib = 1
cached = [fibPrev, fib]

for curr in range(1, n):
    fibOld = fib
    fib = (fib + fibPrev) % m
    fibPrev = fibOld

    if fibPrev == 0 and fib == 1:
        cached.pop()
        break
    else:
        cached.append(fib)

offset = n % len(cached)
sys.stdout.write(str(cached[offset]))
python ~/Work/python/learning/fibonacci.py
1000000000001 99999
63715
Process finished with exit code 0

Исправление Adonai, :

Решение на Питоне (спасибо за подсказку про Пизано)

import sys

lineIn = sys.stdin.readline().split(" ")
n = int(lineIn[0])
m = int(lineIn[1])

fibPrev = 0
fib = 1
cached = [fibPrev, fib]

for curr in range(1, n):
    fibOld = fib
    fib = (fib + fibPrev) % m
    fibPrev = fibOld

    if fibPrev == 0 and fib == 1:
        cached.pop()
        break
    else:
        cached.append(fib)

offset = n % len(cached)
sys.stdout.write(str(cached[offset]))

Исходная версия Adonai, :

Решение на Питоне (спасибо за подсказку про Пизано)

import sys

lineIn = sys.stdin.readline().split(" ")
n = int(lineIn[0])
m = int(lineIn[1])

fibPrev = 0
fib = 1
cached = [fibPrev, fib]

for curr in range(1, n):
    fibOld = fib
    fib = (fib + fibPrev) % m
    fibPrev = fibOld

    if fibPrev == 0 and fib == 1:  # start check
        cached.pop()
        break
    else:
        cached.append(fib)

offset = n % len(cached)
sys.stdout.write(str(cached[offset]))