package com.fei.projecteuler;

import java.math.BigInteger;
import java.util.HashSet;

public class Part2 {

	// Non-abundant sums
	public static void q023() {
		
	}
	
	
	// 1000-digit Fibonacci number
	public static void q025() {
//		for(int i = 1; ; i++) {
//			BigInteger t = BigInteger.valueOf(fibonacci(i));
//			if (t.toString().length() >= 10) {
//				System.out.println(i);
//				break;
//			}
//		}
		
		BigInteger lowerthres = BigInteger.TEN.pow(10 - 1);
		BigInteger upperthres = BigInteger.TEN.pow(10);
		BigInteger prev = BigInteger.ONE;
		BigInteger cur = BigInteger.ZERO;
		int i = 0;
		while (true) {
			// At this point, prev = fibonacci(i - 1) and cur = fibonacci(i)
			if (cur.compareTo(lowerthres) >= 0) {
				System.out.println(i);
				break;
			}
			else if (cur.compareTo(upperthres) >= 0)
				throw new RuntimeException("Not found");
			
			BigInteger temp = cur.add(prev);
			prev = cur;
			cur = temp;
			i++;
		}
	}
	
	public static long fibonacci(long n) {
		if(n <= 1) {
			return n;
		}
		return fibonacci(n - 1) + fibonacci(n - 2);
	}
	
	//Distinct powers
	public static void q029() {
		HashSet<BigInteger> dis = new HashSet<BigInteger>();
		int count = 0;
		for (int i = 2; i <= 100; i++) {
			for (int j = 2; j <= 100; j++) {
				BigInteger tem = BigInteger.valueOf(i).pow(j);
				if (!dis.contains(tem)) {
					dis.add(tem);
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		q029();
	}

}

@@ -1064,16 +1064,17 @@
 %09%7D%0A%09%0A%09//
+ 
 Distinct
@@ -1081,16 +1081,16 @@
  powers%0A
-
 %09public 
@@ -1416,16 +1416,559 @@
 );%0A%09%7D%0A%09%0A
+%09// Digit fifth powers%0A%09public static void q030() %7B%0A%09%09int num = 0;%0A%09%09// As stated in the problem, 1 = 1%5E5 is excluded.%0A%09%09// If a number has at least n %3E= 7 digits, then even if every digit is 9,%0A%09%09// n * 9%5E5 is still less than the number (which is at least 10%5En).%0A%09%09for (int i = 2; i %3C 1000000; i++) %7B%0A%09%09%09if (i == digitsSum(i)) %7B%0A%09%09%09%09num += i;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09System.out.println(num);%0A%09%7D%0A%09%0A%09public static int digitsSum(int n) %7B%0A%09%09int sum = 0;%0A%09%09while(n != 0) %7B%0A%09%09%09int s = n %25 10;%0A%09%09%09sum += Math.pow(s, 5);%0A%09%09%09n = n / 10;%0A%09%09%7D%0A%09%09return sum;%0A%09%7D%0A%09%0A%09//%0A
 %09%0A%09publi
@@ -2044,18 +2044,18 @@
 tub%0A%09%09q0
-29
+30
 ();%0A%09%7D%0A%0A

add q030