decadence

個人のメモ帳

Project Euler 25

Bravo! Now that you have solved 25 problems you have achieved what 80.62% of members have failed to do and have advanced to level 1. Good luck as you continue.
そんなわけでやっと25問

フィボナッチ数列で1000桁になる最初の項の番号

  • Ω

1000桁だろうと物ともしないBigIntegerさんさすがっす

import java.math.BigInteger;

class Sample{
	public static void main(String[] args){
		fib(new BigInteger("1"),new BigInteger("1"),2);
	}
	private static void fib(BigInteger bi1, BigInteger bi2, int count) {
		if(String.valueOf(bi2).length() >= 1000){
			System.out.println(count);
			System.exit(0);
		}
		fib(bi2, bi1.add(bi2), count+1);
	}
}
広告を非表示にする