-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
46 lines (36 loc) · 1.19 KB
/
Main.java
File metadata and controls
46 lines (36 loc) · 1.19 KB
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
43
44
45
46
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int N = Integer.parseInt(input[0]);
int L = Integer.parseInt(input[1]);
List<Integer> ans = new ArrayList<>();
ans = Main.search(N, L);
for(int num : ans){
System.out.print(num + " ");
}
br.close();
}
public static List search(int N, int L){
List<Integer> ans = new ArrayList<>();
for(int i = L; i<101; i++){
// Sum = n( 2a + (n-1)d ) / 2
// d=1, Sum=N, n=i
// a = (2N -i(i-1)) / 2i
if((2*N >= i*(i-1)) && (2*N -i*(i-1))%(2*i) == 0) {
int first = ( 2*N - i*(i-1) ) / (2*i);
for(int add = 0; add < i; add++){
ans.add(first+add);
}
return ans;
}
}
ans.add(-1);
return ans;
}
}