PrasannaBalaji's blog

By PrasannaBalaji, history, 2 months ago, In English,

I am unable to understand the problem please someone explain me in simple terms

click here for the problem

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PrasannaBalaji (previous revision, new revision, compare).

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Something like this maybe:

int main (void)
{
    int Q; cin >> Q;

    while (Q--)
    {
        int N; cin >> N;
        if (N == 1 || N == 2)
            cout << "2\n";
        else if (N & 1)
            cout << "1\n";
        else
            cout << "0\n";
    }

    return 0;
}

Please don't post all bold or caps. It hurts the eye...

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PrasannaBalaji (previous revision, new revision, compare).

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

As for the question, all we need to do is with a given number of sticks, form an addition equation of 2 numbers and output the additional sticks needed. The minimal equation that we can form is |+|=|| and we would need 4 matches. Looking at this mathematically, we would always need even number of sticks as RHS == LHS always. The LHS part needs (answer)/2 sticks and RHS would need (answer)/2. The solution approach goes like, if we have even number of matches => we don't need additional sticks (hence 0) if odd => we need 1 match to make it even (hence 1).

Hope you got what you needed :)