What woulde be the approch for this SPOJ.com - Problem POWPOW question on spoj
links from topcoder, codechef, spoj, github, blogger and stackoverflow. i hope those links gonna help you.