-
Notifications
You must be signed in to change notification settings - Fork 0
/
atlanta.c
49 lines (37 loc) · 959 Bytes
/
atlanta.c
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
/*@Author: Guilherme Cardoso <guilherme.cardoso-oliveira@unesp.br>
@since : 2023-09-01 */
#include <stdio.h>
#include <stdbool.h>
#include<math.h>
/* Formulas:
* A = 2 * (L + C) - 4
* B = (L - 2) * (C - 2)
* (L * C) = (A + B) => C = (A + B) / L
*/
bool equalA(int A, float L, float C) {
return A == 2 * (L + C) - 4;
}
bool equalB(int B, float L, float C) {
return B == (L - 2) * (C - 2);
}
int main() {
int A, B;
float L, C;
scanf("%d %d", &A, &B);
int limite = (int) (A + B) / 2;
bool found = false;
for(int i=2; i <= limite; i++) {
L = (float) i;
C = (float) (A + B) / L;
if(equalA(A, L, C) && equalB(B, L, C)) {
found = true;
break;
}
}
float min = fmin(L, C);
float max = fmax(L, C);
if(!found) printf("-1 -1");
else printf("%d %d", (int) min, (int) max);
system("pause");
return 0;
}