題意:
(from luckycat)
解法: 大數運算直接找。
TAG: BigNum
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10183 - How Many Fibs? | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/05/09 | |
*/ | |
import java.util.*; | |
import java.math.*; | |
public class Main { | |
public static void main( String[] args ) { | |
Scanner input = new Scanner( System.in ); | |
BigInteger[] fibs = new BigInteger[505]; | |
String sa, sb; | |
BigInteger a, b; | |
int cnt; | |
fibs[0] = fibs[1] = BigInteger.ONE; | |
for( int i=2; i <= 500; ++i ) | |
fibs[i] = fibs[i-1].add(fibs[i-2]); | |
while( input.hasNext() ) { | |
sa = input.next(); | |
sb = input.next(); | |
if( sa.equals("0") && sb.equals("0") ) | |
break; | |
a = new BigInteger( sa ); | |
b = new BigInteger( sb ); | |
cnt = 0; | |
for( int i=1; i <= 500; ++i ) { | |
if( fibs[i].compareTo(a)>=0 && fibs[i].compareTo(b)<=0 ) | |
++cnt; | |
} | |
System.out.println(cnt); | |
} | |
input.close(); | |
} | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽