spoj 3377. A Bug’s Life | BUGLIFE

simple bfs problem. the one thing you have to take care is the disjoint groups in the graph.. i got a wrong answer for printing No Suspicious bugs found! instead of No suspicious bugs found!..



spoj 16254. Running Median Again | RMID2

i’m in the grey area for 2 days, unable to figure out what is wrong about the algo. the algo is to maintain two priority queues(with different orders) of equal sizes or a +1 diff. and print the median. but i got fixated on sizes and forgot about rearranging the elements.


91. Two squares or not two squares | TWOSQRS

simple one, after you get to know about the Fermat’s Theorem…. and also if n = 4*k + 3, it can never be a sum of two squares.

even^2 + even^2 = 4*k

odd^2 + even^2 = 4*k + 1

odd^2 + odd^2 = 4*k + 2

Fermat’s Theorem: A number n is a sum of two squares if and only if all prime factors of n of the form 4m+3 have even exponent in the prime fatorization of n.