Posts

Showing posts from December, 2015

Euler Problem 31 ...

It's just a integer partition. public class Test { static int count = 0; public static void main(String[] args) { partition(200, 200); System.out.println(count); } public static void partition(int n, int max) { if (n == 0) { count++; return; } for (int i = Math.min(max, n); i >= 1; i--) { if (i == 200 || i == 100 || i == 50 || i == 20 || i == 10 || i == 5 || i == 2 || i == 1) partition(n - i, i); } } } 73682 Job Finished in 0.02 seconds 정수론에서 나오는 자연수 분할 문제 ..

Euler 40 for Java: Finding the nth digit of the fractional part of the irrational number

Simply, the Integer array can be used to write digits. public class Test { static int[] x = new int[1000000]; static int index = 0; public static void main(String[] args) { for (int i = 1; i < x.length; i++) { if(index >= x.length) break; append(i); } System.out.println(d(1) * d(10) * d(100) * d(1000) * d(10000) * d(100000) * d(1000000)); } private static int d(int i) { return x[i - 1]; } private static void append(int n) { String a = String.valueOf(n); for(int i = 0; i < a.length(); i++) { if(index >= x.length) break; x[index] = Integer.valueOf(String.valueOf(a.charAt(i))); index++; } } }