Brain Teaser

T : Number of test cases

M: value of M

N: Number of strings

For each string, ascii value of each character of the string is raised to M and multiplied together. For each test case the sum of above values  is ODD or EVEN



10    2

ac ab




TIP: Challenge lies in finding the solution without doing all the mathematical operations mentioned in the question. (yes, also called optimizing..!)





T = int(raw_input())
while T>0:
    T = T - 1
    tmp = raw_input()
    M = int(tmp.split()[0])
    K = int(tmp.split()[1])
    tmp = raw_input()
    final_odd = False
    for s in tmp.split():
        odd = None
        for i in s:
            if ord(i)%2==0:        # the power is even
                odd = False
            else:                # the power is odd
                if odd==None:            # if odd is True, odd*odd=odd
                    odd = True
        # odd + odd = even
        # odd + even = odd
        # even + even = even
        if final_odd != odd:
            final_odd = True
            final_odd = False
    if final_odd:
        print "ODD"
        print "EVEN"

Published by


A strong believer of: 1. Knowledge is power 2. Progress comes from proper application of knowledge 3. Reverent attains wisdom 4. For one's own salvation, and for the welfare of the world

Leave a Reply

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

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

Facebook photo

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

Connecting to %s