Advertisement
ruhan008

Python Assignment 5

Feb 2nd, 2024
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import math
  2.  
  3. fibo_1 = 1
  4. fibo_2 = 1
  5.  
  6. index_1000digit = 0
  7. index_10000digit = 0
  8.  
  9. index = 3
  10.  
  11. while(1):
  12.    
  13.     fibo_n = fibo_1 + fibo_2
  14.     power10 = int(math.log10(fibo_n))
  15.  
  16.     if(power10 == 999 and index_1000digit == 0):
  17.         index_1000digit = index
  18.  
  19.     elif(power10 == 9999 and index_10000digit == 0):
  20.         index_10000digit = index
  21.         break;
  22.  
  23.     fibo_1 = fibo_2
  24.     fibo_2 = fibo_n
  25.     index = index + 1
  26.  
  27. print("Index for 1st Fibonacci number with 1000 digits is:", index_1000digit)
  28. print("Index for 1st Fibonacci number with 10000 digits is:", index_10000digit)
  29.  
  30. # OUTPUT:
  31.  
  32. # Index for 1st Fibonacci number with 1000 digits is: 4782
  33. # Index for 1st Fibonacci number with 10000 digits is: 47847
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement