Codechef June Challenge

Complete : Chef and Subarray
Screenshot from 2014-06-07 09:57:11

Complete : Guessing Game

Screenshot from 2014-06-07 10:47:29

Advertisements

4 thoughts on “Codechef June Challenge

  1. I presume that you are using brute force method for finding the Irreducible fraction, so I stress this link. Read on and I am promising that you will find a faster algorithm to find the irreducible fraction.
    If not, i think you are correct. Try after some time.
    I am struggling too hard for third one 😦

    Like

  2. now thanks to gcd function I dont get that error still it says incorrent. The thing is I feel there is something worng with type of i/o that my program gives. Can you please check the code and tell if its a logical fault or fault with my i/o (if it is with i/o please tell the correct way)…

    #include
    #include

    using namespace std;
    unsigned int hcf(unsigned long a, unsigned long b) {
    if (b == 0) {
    return a;
    } else {
    return hcf(b, a % b);
    }
    }
    int main()
    {
    // freopen(“out.txt”,”w”,stdout);
    // freopen(“in.txt”,”r”,stdin);
    unsigned long T,N[100000],M[100000],i,j,no,ne,mo,me,n1,n2,k;
    cin>>T;
    for(i=0;i>N[i]>>M[i];
    for(i=0;i<T;i++)
    {
    no = ne = N[i]/2;
    if(N[i]%2!=0) no++;
    mo = me = M[i]/2;
    if(M[i]%2!=0) mo++;
    n1 = ne*mo + no*me;
    n2 = N[i]*M[i];
    do
    {
    k = hcf(n1,n2);
    n1/=k;
    n2/=k;
    }while(k!=1);
    cout<<n1<<"/"<<n2<<endl;
    }
    }

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s