import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
int n = Integer.parseInt(br.readLine());
String m = "";
for (int i = 1; i < n + 1; i++) {
String[] str = br.readLine().split(" ");
int x = Integer.parseInt(str[0]);
int y = Integer.parseInt(str[1]);
long arr[] = div(x - y, y);
sb.append("Case #").append(i).append(":");
for (int j = 0; j < arr.length; j++) {
sb.append(" ").append(arr[j]);
}
sb.append("\n");
}
System.out.print(sb);
}
static long[] div(int x, int r) {
LinkedList<Long> list = new LinkedList<Long>();
long[] arr;
if (x==0) {
arr = new long[1];
arr[0] = 0;
return arr;
}
if (r > x) {
return new long[0];
}
for (long i = 1; i < Math.sqrt(x) + 1; i++) {
if (x % i == 0) {
if (i > r && !list.contains(i)) {
list.add(i);
}
if ((x / i) > r) {
if(!list.contains(x/i))
list.add(x / i);
}
}
}
arr = new long[list.size()];
for (int i = 0; i < list.size(); i++) {
arr[i] = list.get(i);
}
Arrays.sort(arr);
return arr;
}
}
No comments:
Post a Comment