题目
代码
public class lqb13_A组02寻找整数 {
public static void main(String[] args) {
long[] a = {0, 0,
1, 2, 1, 4, 5, 4, 1, 2, 9, 0, 5, 10,
11, 14, 9, 0, 11, 18, 9, 11, 11, 15, 17, 9,
23, 20, 25, 16, 29, 27, 25, 11, 17, 4, 29, 22,
37, 23, 9, 1, 11, 11, 33, 29, 15, 5, 41, 46};
long start = 1;
long step = 1;
for (int i = 2; i < a.length - 1; i++) {
step = lcm(step, i);
while (start % (i + 1) != a[i + 1]) {
start += step;
}
}
System.out.println(start);
}
public static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
}