-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolve10.java
42 lines (31 loc) · 904 Bytes
/
Solve10.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.fpp.solutions;
public class Solve10 {
public int[] solve10() {
int xy[] = {0, 0};
int x = 1;
int y = 1;
int factorialSum = 0;
// System.out.println(factorial(34));
while (factorialSum != factorial(10)) {
x++;
for (int i = 1; i <= x; i++) {
factorialSum = factorial(x) + factorial(i);
// System.out.println(x + "-" + factorial(x) + " + " + i + "-" + +factorial(i) + " = " + factorialSum);
if (factorialSum == factorial(10)) {
y = i;
xy[0] = x;
xy[1] = y;
break;
}
}
}
return xy;
}
int factorial(int n) {
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
}