Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Cook off Jan 2014 - Subtraction Game

$
0
0

the question for the solution below is -

http://www.codechef.com/problems/GAMEAAM

Now...

The following code is working fine for the test cases but giving wrong answer on submission. What is the mistake that i am doing? Is my method wrong for the question?

#include<iostream>
#include<stdio.h>
using namespace std;
int func(long long int a,long long int b)
{
    int freq=0;
    if(a<b)
        swap(a,b);
    if(a%b==0)
        freq++;
    else
    {
        freq++;
        freq+=func(b,a%b);
    }
    return freq;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int a,b;
        int arr[n];
        int sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>a;
            cin>>b;
            arr[i]=func(a,b);
            sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>