Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Mat
- */
- package problem.pkg25;
- import java.math.BigInteger;
- public class Problem25 {
- public static void main(String[] args) {
- // Start of the Fibonacci sequence
- BigInteger A = BigInteger.ONE;
- BigInteger B = BigInteger.ONE;
- // to make DIGITS contain 10^999 which is a number that has 100 digits
- final BigInteger DIGITS = new BigInteger("10").pow(999);
- // for debuging to make sure the number is the correct number of digits
- String s1 = DIGITS.toString();
- System.out.println("Number of digits in s1: " + s1.length());
- // loop starts at 2 as sequence has been set at both ones
- for(int i = 2;;){
- A = A.add(B);
- i++;
- if(A.compareTo(DIGITS) >= 0){
- System.out.println("i is: " + i );
- System.out.println("A is: " + A.toString() );
- break;
- }
- B = B.add(A);
- i++;
- if(B.compareTo(DIGITS) >= 0){
- String s2 = B.toString();
- System.out.println("i is: " + i + "\n" );
- System.out.println("B is: " + B.toString());
- break;
- }
- }
- }
- }
- /* output
- * Number of digits in s1: 1000
- * i is: 4782
- * B is: 1070066266382758936764980584457396885083683896632151665013235203375314
- * 5206046940406218891475824897926578046948881775919574843364666725699595129960
- * 3046126274809248218614406943305123477444275027378175308757939166619214925918
- * 6759553966422837148943113074699503439547001985432609723067290192870526447243
- * 7261177158218255484911205250132014786129659313817922355596574520395061375514
- * 6783754322911960212993404826070617539770684706820289548690266618543512452190
- * 0369480641357447470911707619766945691070098024393439617474103736912503231365
- * 5321647736970231677550515951735184605799549194109677783732296657965816465139
- * 0348815425631018422419025984608800011018625555024549393711365165703944762958
- * 4714548523425950428582425306083544435428212611008992863795048006894330309773
- */
Advertisement
Add Comment
Please, Sign In to add comment