![:wink:](./images/smilies/icon_wink.gif)
Bye
Riyad
Moderator: Board moderators
Code: Select all
701 701 1059 1417 2312 0
0
Code: Select all
179
Code: Select all
Code: Select all
-666 169 0
-650 -164 0
-202 157 0
976 -632 0
762 531 0
615 234 0
-244 -722 0
-145 716 0
-783 482 0
721 421 0
-316 -721 0
0
Code: Select all
835
486
359
1608
231
381
478
861
1265
300
405
Code: Select all
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector< int >v;
int GCD(int y, int x){
if(!x) return 0;
int store;
while(y%x != 0)
{
store = y%x;
y = x;
x = store;
}
return x;
}
int main(){
int input, pre, post, size, i;
while((cin >> input) && input){
v.push_back(input);
while((cin >> input) && input){
v.push_back(input);
}
sort(v.begin(), v.end());
size = v.size(); //cout << size << endl;
for(i = 1; i<size; i++){
if(i == 1){
pre = v[i] - v[0]; //cout << v[i] << endl;
}
else{
post = v[i] - v[0];
if(post >= pre)
pre = GCD(post, pre);
else
pre = GCD(pre, post);
}
}
cout << pre << endl;
v.clear();
}
return 0;
}
Code: Select all
2 2 4 0
0
Input : 14 -22 17 -31 -124 0
output: 3
Will someone plz explain this ?14%3 = 2
whereas -22%3 = 1