-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcddo.cpp
More file actions
40 lines (35 loc) · 763 Bytes
/
gcddo.cpp
File metadata and controls
40 lines (35 loc) · 763 Bytes
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
#include<iostream>
#include<vector>
using namespace std;
int solve(vector<int>& A);
int gcd(int a, int b);
int gcd(int a, int b)
{
if (a == 0) return b;
return gcd(b % a, a);
}
int solve(vector<int>& A) {
vector<int> pgcd(A.size(),0);
vector<int> sgcd(A.size(),0);
int ans = 0;
pgcd[0] = A[0];
sgcd[A.size() - 1] = A[A.size() - 1];
for (int i = 1,j = (A.size() - 2); i < A.size(); i++,j--)
{
pgcd[i] = gcd(pgcd[i], A[i]);
sgcd[j] = gcd(sgcd[j], A[j]);
}
for (int i = 0, j = (A.size() - 1); i < A.size(); i++, j--)
{
cout << pgcd[i] << " " << sgcd[j];
cout << endl;
}
return ans;
}
int main()
{
vector<int> A = { 12, 15, 18 };
cout << "Hello delete one\n";
cout << "Max value of GCD : " << solve(A) << endl;
return 0;
}