-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinduction4.cpp
60 lines (54 loc) · 1.15 KB
/
induction4.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
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
bool search(int a[], int len, int item);
int main()
{
int t;
cin >> t;
int input[128]; int x[128], x1 = 0, X, y[128], y1 = 0, Y;
int n = 0, tmp;
// to get single-line input
while( n < t && scanf( "%d", &tmp) != EOF)
{
input[n++] = tmp;
}
// to find x
int max = 0;
for (int i = 0; i < t; i++)
{
if (input[i] > max) {max = input[i];}
}
X = max;
// to find factors of x
for (int i = 0; i < t; i++)
{
if (X % input[i] == 0 && search(x, t, input[i]) == false)
{
x[x1++] = input[i];
}
else {y[y1++] = input[i];}
}
// to find y
max = 0;
for (int i = 0; i < y1; i++)
{
if (y[i] > max) {max = y[i];}
}
Y = max;
cout << X << " " << Y << endl;
return 0;
}
bool search(int a[], int len, int item)
{
bool flag = false;
for (int i = 0; i < len; i++)
{
if (a[i] == item)
{
flag = true;break;
}
}
return flag;
}