1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;

public class fib {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String find = in.nextLine();
		in.close();
		int length = find.length();
		long limit = 0;
		long div = 0;
		if (length == 1) {
			limit = 60;
			div = 10;
		} else if (length == 2) {
			limit = 300;
			div = 100;
		} else {
			limit = 15;
			div = 10;
			for (int i = 1; i < length; i++) {
				limit *= 10;
				div *= 10;
			}
		}
		long lfind = Long.valueOf(find).longValue();

		long a = 0;
		long b = 1;
		long c = 1;
		long k = 2;
		while (c < div/10) {
			a = b;
			b = c;
			c = a + b;
			c %= div;
			k++;
		}

		boolean found = false;
		for (long i = 0; i <= limit; i++) {
			if (c == lfind) {
				System.out.println(k+i);
				found = true;
				i = limit + 1;
			}
			a = b;
			b = c;
			c = a + b;
			c %= div;
		}

		if (!found) {
			System.out.println("NIE");
		}
	}

}