here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Monday 20 October 2014

Crucial Equation

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;
}

6 comments:

  1. I understand the logic , but don't know how it works .... please explain if possible.

    ReplyDelete
  2. #include
    using 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;
    }

    ReplyDelete
  3. #include
    using 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?

    ReplyDelete
  4. #include
    using 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;
    }

    ReplyDelete
  5. #include
    using 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;
    }

    ReplyDelete