// The idea is to store the FIB number in a large integer array, and then look for import Java in two parts. util. *; import Java. math. *; import Java. io. *; Class main {public static void main (string [] ARGs) {// todo auto-generated method stub biginteger [] f = new biginteger [500]; f [0] = f [1] = biginteger. one; For (INT I = 2; I <500; I ++) f [I] = f [I-1]. add (F [I-2]); F [0] = biginteger. zero; vertex SC = new vertex (New bufferedinputstream (system. in); biginteger L, R; while (SC. hasnext () {L = SC. nextbiginteger (); r = SC. nextbiginteger (); If (L. compareto (biginteger. zero) = 0 & R. compareto (biginteger. zero) = 0) break; int ansl = arrays. binarysearch (F, L); int ansr = arrays. binarysearch (F, R); If (ansl <0) ansl =-ansl-2; If (ansr <0) ansr =-ansr-2; If (arrays. binarysearch (F, L)> 0) ansl --; system. out. println (ansr-ansl );}}}Iron vegetable cannot exceed limit
The usage of arrays. binarysearch () is attached:
Public static int binarysearch (object [] A, object key) uses the Binary Search Method to search for a specified array to obtain the specified object. Before this call, the array must be sorted in ascending order (using the sort (object []) method) according to the natural order of the elements ). If the array is not sorted, the result is uncertain. (If an array contains elements that cannot be compared with each other (for example, strings and integers), the array cannot be sorted in the natural order of its elements, so the result is uncertain .) If the array contains multiple elements that are equal to the specified object, you cannot guarantee which one is found.
Parameter: A-array key to be searched-value to be searched
Return: if it is included in an array, the index of the search key is returned; otherwise (-(insertion point)-1) is returned ). The insert point is defined as the point where the key is inserted into the array:
Element index. If all elements in the array are smaller than the specified key, the value is a. length. Note that this ensures that when and only when this key is found, the returned value is greater than or equal to 0.
Otherwise, the return value (-(insert point)-1) must be noted: If the queried value is smaller than the value in the array
The result (-(0)-1 is-1). If the queried value is greater than the maximum value in the array. The result is (-(its index value)-1 and the result is-(1 + index value ))
Hdu1316 how many fibs?