/ **
* compareTo: returns -1, 0, or 1 according to whether the value is less than, equal to, or greater than val;
public int compareTo (BigInteger val)
compares this BigInteger with the specified BigInteger.
For each method for each of the six Boolean comparison operators (<, ==,>,> =,! =, <=)
, This method is given priority.
The recommended statement to perform these comparisons is: (x.compareTo (y) <op> 0),
where <op> is one of the six comparison operators.
* /
/ **
* and: && equivalent to c ++, and;
* /
import java.io. *; import java.util. *; import java.math.*; public class Main { /** * @xqq */ public int an(BigInteger a, BigInteger b, BigInteger sa, BigInteger sb) { int years = 0; if(a.compareTo(sa) >= 0 && a.compareTo(sb) <= 0) { ++ years; } if(b.compareTo(sa) >= 0 && b.compareTo(sb) <= 0) { ++ years; } for(;;) { BigInteger c = a.add(b); a = b; b = c; if(b.compareTo(sa) >= 0 && b.compareTo(sb) <= 0) { ++ years; } if(b.compareTo(sb) > 0) { return ans; } } } public static void main(String[] args) throws Exception { // Define and open the input file Scanner cin = new Scanner(System.in); Main e = new Main(); BigInteger a = BigInteger.valueOf(1); BigInteger b = BigInteger.valueOf(2); BigInteger in; BigInteger sb; BigInteger zero = BigInteger.ZERO; while(cin.hasNext()) { set = cin.nextBigInteger (); sb = cin.nextBigInteger (); if(sa.compareTo(zero) == 0 && sb.compareTo(zero) == 0) { break; } System.out.println (e.an (a, b, sa, sb)); } cin.close (); // Close input file } }
HDU 1316 How Many Fibs? (Java, simple questions, large numbers), cloth button, bubuko.com
HDU 1316 How Many Fibs? (Java, simple questions, large numbers)