-
Notifications
You must be signed in to change notification settings - Fork 14
/
10407.cpp
62 lines (59 loc) · 1.43 KB
/
10407.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
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
using namespace std;
int gcd(int a, int b){
if(b > a) return gcd(b, a);
if(b==0) return a;
else return gcd(b, a%b);
}
int main(){
while(true){
int arr[1000], i=0, n=1;
cin>>arr[0];
if(arr[0]==0)
break;
while(true){
cin>>arr[n];
if(arr[n] == 0)
break;
n++;
}
int gd = gcd(arr[0], arr[1]);
if(arr[0]==arr[1] && n==2){
cout<<gd<<endl;
continue;
}
for(i=1; i<n; i++)
arr[i] = (int)abs(arr[i] - arr[i-1]);
for(i=2; i<n; i++)
gd = gcd(gd, arr[i]);
cout<<gd<<endl;
}
return 0;
}