Created
January 27, 2019 05:16
-
-
Save ufocoder/1f213b1ba802e14e554292841595c9ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib_mod(num, mod): | |
if mod == 1: | |
return 0 | |
seq = [0, 1] | |
prev = 0 | |
curr = 1 | |
while True: | |
prev, curr = curr, (prev + curr) % mod | |
seq.append(curr) | |
if prev == 0 and curr == 1: | |
break | |
seq = seq[:-2] | |
return seq[num % len(seq)] | |
def main(): | |
n, m = map(int, input().split()) | |
print(fib_mod(n, m)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment