forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB0021.cpp
More file actions
37 lines (33 loc) · 711 Bytes
/
B0021.cpp
File metadata and controls
37 lines (33 loc) · 711 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
// Problem Code: RECIPE
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void cuttingRecipes(vector<int> &ingredients){
int gcd = ingredients[0];
for(int i=1 ; i<ingredients.size() ; i++)
gcd = __gcd(ingredients[i], gcd);
if(gcd == 1)
return;
for(int i=0 ; i<ingredients.size() ; i++)
ingredients[i] /= gcd;
}
int main()
{
int T, N, num;
vector<int> ingrediants, results;
cin >> T;
for(int i=1 ; i<=T ; i++){
cin >> N;
for(int i=0 ; i<N ; i++){
cin >> num;
ingrediants.push_back(num);
}
cuttingRecipes(ingrediants);
for(int i=0 ; i<ingrediants.size() ; i++)
cout << ingrediants[i] << " ";
cout << endl;
ingrediants.clear();
}
return 0;
}