ZA. Greatest Common Divisor (GCD)
Problem link Click here
Score: 1
CPU: 1s
Memory: 256MB
CPU: 1s
Memory: 256MB
You will be given two positive integers
A
and B
. You have to calculate the GCD
of given numbers.
Input
First you will be given a positive integer
Output
For each test case you have to print the
First you will be given a positive integer
T (1< T < 100)
, the number of test case. Each test case will contain two positive numbers A
and B ( 0 < A , B < 100000)
. Output
For each test case you have to print the
GCD
of A
and B
in different lines.Sample
Input | Output |
---|---|
2
2 4
6 15
Solutin
#include<stdio.h>
int main()
{
int x,y,m,i,d,j;
scanf("%d",&d);
for(j=1;j<=d;j++){
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--){
if(x%i==0 && y%i==0){
printf("%d\n",i) ;
break;
}
}
}
return 0;
}
| 2 3 |
x,y,m,i,d,j এগুলো কি বুঝাচ্ছে একটু ক্লিয়ার করে দিন
ReplyDelete