OPBIT - Operation Bits
Operation bits - A new operation conducted by the secret team currently working on a project on security enhancement. Mr.Abay, the team head, has found a new pattern on the perfect squares. This can be used as a outer cover for his project as its securing power is low. So he assign you this problem to find the key based on the given conditions:
"An two adjacent perfect squares have their absolute difference as an odd number except when a and b are equal. Your task is to find the key which is deined as:
key(a,b) where a and b are perfect squares is ( ( AND( absolute difference betwen every adjacent perfect squares in [a,b]) ) AND ( XOR( absolute difference betwen every adjacent perfect squares in [a,b]) ) )"
Find the key for the given inputs :)
The input begins with a number T (1<=T<=1000) where T is the number of testcases.
T lines follow
Each line has two numbers a and b (0 < a <= b <= 10^6)
It is assured that a and b are perfect squares.
For each test case print the corresponding key
for test case 1 we have key=(3)&(3)=3
Last edit: 2016-04-05 15:59:06
Brute force gives AC even in Python :)
Brute force gave AC here. But my O(1) solution gave WA! :-(
@ Benkindersophobia - Please check submission ID 14374408. I am pretty sure my code is correct.
Same algo TLE in python, AC in C++
Silly mistakes coast me 2 WA...Nice problem..... :)
Ac in one go........
when a==b,answer is 0 as 0&0=0
weak test cases..