193E - Fibonacci Number - CodeForces Solution


brute force math matrices *2900

Please click on ads to support us..

Python Code:

n,m,limn,f,L=1000,12000,int(10**13),int(input()),[]

def F(i):
	if i==0:
		return (0,1)
	a,b=F(i>>1)
	a,b=((2*a*b-a*a)%n,(b*b+a*a)%n)
	if i&1:
		a,b=(b%n,(a+b)%n)
	return (a,b)

for i in range(m):
	if F(i)[0]==f%n:
		L.append(i)

while n<limn:
	n*=10;
	T=[]
	for i in L:
		for j in range(10):
			if F(i+j*m)[0]==f%n:
				T.append(i+j*m)
	L=T;m*=10
	if L==[]:
		break

if L==[]:
	print(-1)
else:
	L.sort()
	print(L[0])


Comments

Submit
0 Comments
More Questions

1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You