// UVa 10407 - Simple division
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int a, int b) {
if (a == 0)
return b;
else
return gcd(b % a, a);
}
int main() {
int a;
cin >> a;
while (a) {
// input
vector<int> v;
do {
v.push_back(a);
cin >> a;
} while (a);
// prepare
unique(v.begin(), v.end());
// gen d
vector<int> d;
for (int i = 1; i < v.size(); i++)
d.push_back(v[i] - v[i - 1]);
// gcd
int g = abs(d[0]);
for (int i = 1; i < d.size(); i++)
g = gcd(g, abs(d[i]));
cout << g << endl;
cin >> a;
}
return 0;
}
Tuesday, July 28, 2015
UVa 10407 - Simple division
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment