pairwise operations on set

Recently I have encountered many questions which require performing some operations like XOR, or some f(x) pairwise on a Set…

by pairwise I mean, if set is {2, 4, 6}

then required O/P is 2^4 + 4^6 + 6^2 or f(2,4) + f(4,6) + f(6,2)

How to handle such questions, someone help…
Also can such questions be solved using DP?

here is the problem i think fit well for your question : http://www.spoj.com/problems/FRND/

i don’t want to post code here , i will recommend you to solve this problem first
(used in codechef lunchtime conetest)

Problem Link->Pairwise AND Sum (http://www.codechef.com/LTIME03/problems/AND)

Editorial Link->(http://discuss.codechef.com/problems/AND)

Both problems have same concept .
Hope this help.

yeah that was just one of those problems I faced, also there was one where f(x,y) = gcd(x,y)

btw thanx buddy :slight_smile:
keep up the good work

1 Like
//