-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path049.cpp
51 lines (47 loc) · 962 Bytes
/
049.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
#include <iostream>
//#include <cmath>
#include <climits>
#define BETTER_INF ((unsigned) ~0)
using namespace std;
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n;
long long int a, min, max;
cin >> n;
min = BETTER_INF; max = -1;
for (int i = 0; i < n; i++)
{
cin >> a;
if (a >= max && a % 2 == 0) { max = a; }
if (a <= min && a % 2 != 0) { min = a; }
}
if (min == BETTER_INF && min != 1) { min = -1; }
if (max == -1) { max = -1; }
cout << min << " " << max;
return 0;
}
--------------
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, n1, l, j, rem;
cin >> n >> n1;
if (n > n1) { l = n; j = n1; }
else { l = n1; j = n; }
if (j == 0) { cout << l; return 0; }
if (l%j == 0) { cout << j; return 0; }
rem = l % j;
while (l % j) {
rem = l % j;
l = j;
j = rem;
}
cout << rem;
return 0;
}