package margusmartseppcode.From_30_to_39; public class Problem_34 { public static void main(String[] args) { int fact[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 }; int s = 0, sum = 0; for (int i = 10; i < fact[9] + 1; i++, sum = 0) { for (char c : ("" + i).toCharArray()) sum += fact[Character.getNumericValue(c)]; if (sum == i) s += i; } System.out.println(s); } }
No comments:
Post a Comment