title: Python: Compute a Huge Fibonacci Number Modulo m
body: <pre><code># Uses python3
  # Given two integers n and m, output Fn mod m (that is, the remainder of Fn when divided by m
  def Huge_Fib(n,m):
  
      if n == 0 : return 0
      elif n == 1: return 1
      else:
          a,b = 0,1
          for i in range(1,n):
              a, b = b, (a+b) % m
          print(b);
  
  n,m = map(int, input().split());   
  Huge_Fib(n,m);
  </code></pre>
  
  <p>The code works very well. However, when I run a case as n = 99999999999999999, m = 2, it takes me much time. Do you have any better solutions?</p>