-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCD2.cpp
More file actions
37 lines (37 loc) · 841 Bytes
/
GCD2.cpp
File metadata and controls
37 lines (37 loc) · 841 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
/*
===================================================
Name :- Nishant Raj
Email :- raj.nishant360@gmail.com
College :- Indian School of Mines
Branch :- Computer Science and Engineering
Time :- 02 June 2016 (Thursday) 11:26
===================================================*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int mod(char s[], int divider){
int r = 0;
for(int i = 0 ;s[i] ; i++){
r = r*10 + s[i] - 48;
r = r % divider;
}
return r;
}
int gcd(int a , int b){
return b == 0 ? a : gcd(b , a%b);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int a;
char b[259];
scanf("%d %s",&a , b);
if(a == 0){
printf("%s\n" , b);
continue;
}
printf("%d\n", gcd(a , mod(b , a)));
}
return 0;
}