Editorial for MATTL

PROBLEM LINK:Contest Page | CodeChef

Practice

Author: harsh_beniwal
Tester: harsh_beniwal
Editorialist: harsh_beniwal

DIFFICULTY:

EASY.

PREREQUISITES:

Math,Arrays.

PROBLEM:

Give the Integers L ans R.

Find the total number of even numbers between the given range and check if the total number of even numbers between the given range is Even the print “PASS” else print “FAIL”.

(NOTE:− L ans R are inclusive).

QUICK EXPLANATION:

Just Count the total number of even numbers between the L,R Inclusive. and check if the count is even or odd. If it’s Even Then print “PASS” else “FAIL”

EXPLANATION:

Traverse the array using a single pointer with O(N) Solution. while traversing the array check if the element is event or odd. it the number is event then increment the counter.

Lastly check the counter by (counter % 2 == 0) if the condition is true print “PASS” else print “FAIL”.

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>

using namespace std;

#define ll long long int

int main()

{

int t;

cin>>t;

while(t--)

{

ll l,r,cnt=0;

cin>>l>>r;

for(ll i=l;i<=r;i++)

{

    if(i%2==0)

    {

        cnt++;

    }

}

if(cnt%2==0)

{

    cout<<"PASS"<<"\n";

}

else

{

    cout<<"FAIL"<<"\n";

}  

}

}

Tester's Solution

#include<bits/stdc++.h>

using namespace std;

#define ll long long int

int main()

{

int t;

cin>>t;

while(t--)

{

ll l,r,cnt=0;

cin>>l>>r;

for(ll i=l;i<=r;i++)

{

    if(i%2==0)

    {

        cnt++;

    }

}

if(cnt%2==0)

{

    cout<<"PASS"<<"\n";

}

else

{

    cout<<"FAIL"<<"\n";

}  

}

}

Editorialist's Solution

#include<bits/stdc++.h>

using namespace std;

#define ll long long int

int main()

{

int t;

cin>>t;

while(t--)

{

ll l,r,cnt=0;

cin>>l>>r;

for(ll i=l;i<=r;i++)

{

    if(i%2==0)

    {

        cnt++;

    }

}

if(cnt%2==0)

{

    cout<<"PASS"<<"\n";

}

else

{

    cout<<"FAIL"<<"\n";

}  

}

}

1 Like