Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. mod = False
  2.  
  3. def mult(A, B):
  4.     Ret = []
  5.     Ret.append(A[0] * B[0] + A[1] * B[2])
  6.     Ret.append(A[0] * B[1] + A[1] * B[3])
  7.     Ret.append(A[2] * B[0] + A[3] * B[2])
  8.     Ret.append(A[2] * B[1] + A[3] * B[3])
  9.     if mod:
  10.         for i in range(len(Ret)):
  11.             Ret[i] = Ret[i] % 10**100
  12.     return Ret
  13.  
  14. try:
  15.     while True:
  16.         n = int(input())
  17.         k = 1
  18.         pow_ = 2
  19.         DP = []
  20.         DP.append([1, 1, 1, 0])
  21.         while pow_ <= n:
  22.             DP.append(mult(DP[k - 1], DP[k - 1]))
  23.             pow_ *= 2
  24.             k += 1
  25.         Out = [1, 0, 0, 1]
  26.         while n > 0:
  27.             if n >= pow_:
  28.                 n -= pow_
  29.                 Out = mult(DP[k], Out)
  30.             pow_ //= 2;
  31.             k -= 1
  32.         print (Out[1])
  33.  
  34. except EOFError:
  35.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement