-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoodsequence.cpp
72 lines (55 loc) · 1.25 KB
/
goodsequence.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
72
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
if (a == 0)
return b;
if (b == 0)
return a;
if (a == b)
return a;
if (a > b)
return gcd(a - b, b);
return gcd(a, b - a);
}
int main()
{
int n, a, b, c,d;
cin >> n;
int arr[n];
int newarr[] = {};
int arrsize;
vector<int> vec = {}, newvec = {};
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
for (int j = 0; j < n; j++)
{
vec.clear();b=0;
for (int k = j + 1; k < n; k++)
{
if (arr[k-1] < arr[k] && b<arr[k])
{
a = arr[k-1];
b = arr[k];
c = gcd(a, b);
if (c == 1)
{
vec.push_back(b);
}
}
}
auto it = vec.insert(vec.begin(), a);
for (int l = 0; l < vec.size(); l++)
cout << vec[l] << " ";
cout << endl;
newvec.push_back(vec.size());
}
cout << "\nMax Element = "
<< *max_element(newvec.begin(), newvec.end());
return 0;
}