-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifiedGCD.c
More file actions
35 lines (32 loc) · 792 Bytes
/
ModifiedGCD.c
File metadata and controls
35 lines (32 loc) · 792 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
#include<stdio.h>
int gcd(int a,int b)
{
if(b%a==0) return a;
else return gcd(b%a,a);
}
int main()
{
int a,b,n;
while(3==scanf("%d%d%d",&a,&b,&n))
{
int l,low,high,ans[n];
int GCD=gcd(a,b);
for(l=0,ans[0]=-1;l<n;l++,ans[l]=-1)
{
int i;
scanf("%d%d",&low,&high);
if(low<=GCD && high>=GCD){
ans[l]=GCD;
continue;
}
else if(low>GCD) continue;
else{
int d,temp;
for(d=2,temp=GCD/d;(GCD%d) && temp>=low;d++,temp=GCD/d);
if(temp>=low && temp<=high) ans[l]=temp;
}
}
for(l=0;l<n;l++) printf("%d\n",ans[l]);
}
return 0;
}