Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("text.in");
- ofstream fout("text.out");
- int n, v[100];
- void read(int &n, int v[]) {
- fin >> n;
- for (int i = 0; i < n; i++) {
- fin >> v[i];
- }
- }
- int getGcd(int a, int b) {
- while (a != b) {
- if (a > b) {
- a -= b;
- } else {
- b -= a;
- }
- }
- return a;
- }
- int main() {
- read(n, v);
- int r = v[0];
- for (int i = 1; i < n; i++) {
- r = getGcd(r, v[i]);
- }
- fout << r << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement