problem statement is here
#include<stdio.h>
gcd(int m,int n){
if(n==0)
return m;
else
return gcd(n,m%n);
}
int main(){
int a,b,c,t,g,e=1;
scanf("%d",&t);
while(t--){
scanf("%d %d %d",&a,&b,&c);
g=gcd(abs(a),abs(b));
if(c%g==0)
printf("Case %d: Yes\n",e);
else
printf("Case %d: No\n",e);
e++;
}
return 0;
}
thanks ,
ReplyDeleteI understand the logic , but don't know how it works .... please explain if possible.
ReplyDelete#include
ReplyDeleteusing namespace std;
int gcd(int big,int small)
{
for(int i=small;i>=1;i--)
{
if(big%i==0)
{
return(i);
}
}
}
int main() {
int t;
cin>>t;
int a,b,c;
int g;
for(int i=1;i<=t;i++)
{
cin>>a>>b>>c;
if (a>b)
{g=gcd(a,b);
}
else
{
g=gcd(b,a);
}
if(c%g==0)
{
cout<<"Case "<<i<<": Yes";
}
else
{ cout<<"Case "<<i<<": No";}
cout<<"\n";
}
return 0;
}
#include
ReplyDeleteusing namespace std;
int gcd(int big,int small)
{
for(int i=small;i>=1;i--)
{
if(big%i==0)
{
return(i);
}
}
}
int main() {
int t;
cin>>t;
int a,b,c;
int g;
for(int i=1;i<=t;i++)
{
cin>>a>>b>>c;
if (a>b)
{g=gcd(a,b);
}
else
{
g=gcd(b,a);
}
if(c%g==0)
{
cout<<"Case "<<i<<": Yes";
}
else
{ cout<<"Case "<<i<<": No";}
cout<<"\n";
}
return 0;
}
this code gives wrong answer. why?
#include
ReplyDeleteusing namespace std;
int gcd(int big,int small)
{
for(int i=small;i>=1;i--)
{
if(big%i==0)
{
return(i);
}
}
}
int main() {
int t;
cin>>t;
int a,b,c;
int g;
for(int i=1;i<=t;i++)
{
cin>>a>>b>>c;
if (a>b)
{g=gcd(a,b);
}
else
{
g=gcd(b,a);
}
if(c%g==0)
{
cout<<"Case "<<i<<": Yes";
}
else
{ cout<<"Case "<<i<<": No";}
cout<<"\n";
}
return 0;
}
#include
ReplyDeleteusing namespace std;
int gcd(int big,int small)
{
for(int i=small;i>=1;i--)
{
if(big%i==0)
{
return(i);
}
}
}
int main() {
int t;
cin>>t;
int a,b,c;
int g;
for(int i=1;i<=t;i++)
{
cin>>a>>b>>c;
if (a>b)
{g=gcd(a,b);
}
else
{
g=gcd(b,a);
}
if(c%g==0)
{
cout<<"Case "<<i<<": Yes";
}
else
{ cout<<"Case "<<i<<": No";}
cout<<"\n";
}
return 0;
}