import java.math.BigInteger;
import java.util.Scanner;
public class fib {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String searchFor = scanner.nextLine();
if(searchFor == "0")
System.out.print("0");
else if(searchFor == "1")
System.out.print("1");
BigInteger fib1 = BigInteger.valueOf(0), fib2 = BigInteger.valueOf(1), k = BigInteger.valueOf(2), tmp;
BigInteger maxK = BigInteger.valueOf(1);
BigInteger ten = BigInteger.valueOf(10);
for(int i = 0; i < 100; ++i)
{
maxK = maxK.multiply(ten);
}
maxK = maxK.add(BigInteger.ONE);
String str;
do
{
tmp = fib1;
fib1 = fib2;
fib2 = fib1.add(tmp);
str = fib2.toString();
if(str.length() >= searchFor.length() && str.endsWith(searchFor))
{
System.out.print(k.toString());
return;
}
k = k.add(BigInteger.ONE);
} while(k.compareTo(maxK) < 0);
System.out.print("NIE"); // he he, pozdro jak tu dojdzie
}
}
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 | import java.math.BigInteger; import java.util.Scanner; public class fib { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String searchFor = scanner.nextLine(); if(searchFor == "0") System.out.print("0"); else if(searchFor == "1") System.out.print("1"); BigInteger fib1 = BigInteger.valueOf(0), fib2 = BigInteger.valueOf(1), k = BigInteger.valueOf(2), tmp; BigInteger maxK = BigInteger.valueOf(1); BigInteger ten = BigInteger.valueOf(10); for(int i = 0; i < 100; ++i) { maxK = maxK.multiply(ten); } maxK = maxK.add(BigInteger.ONE); String str; do { tmp = fib1; fib1 = fib2; fib2 = fib1.add(tmp); str = fib2.toString(); if(str.length() >= searchFor.length() && str.endsWith(searchFor)) { System.out.print(k.toString()); return; } k = k.add(BigInteger.ONE); } while(k.compareTo(maxK) < 0); System.out.print("NIE"); // he he, pozdro jak tu dojdzie } } |
English