forked from hackerkid/LightOJ-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1014-Ifter-Party.cpp
72 lines (52 loc) · 910 Bytes
/
1014-Ifter-Party.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
int main()
{
int t;
long long p;
long long q;
long long l;
long long i;
cin >> t;
for (int j = 1; j <= t; j++) {
scanf("%lld", &p);
scanf("%lld", &l);
p = p - l;
vector <long long> a;
vector <long long> b;
for (i = 1; i * i < p; i++) {
if(p % i == 0) {
if(i > l) {
a.push_back(i);
}
if((p / i) > l) {
b.push_back(p / i);
}
}
}
if(i * i == p and i > l) {
a.push_back(i);
}
printf("Case %d: ", j);
for (int i = 0; i < a.size(); i++) {
printf("%lld", a[i]);
if(!(i == a.size() - 1 and b.size() == 0)) {
printf(" ");
}
}
for (int i = b.size() - 1; i >= 0; i--) {
printf("%lld", b[i]);
if(i != 0) {
printf(" ");
}
}
if(a.size() + b.size()) {
printf("\n");
}
else {
printf("impossible\n");
}
}
}