/** * Collecting money via divide-and-conquer method. * * @author (Stefan Edelkamp) * @version (2013) */ public class CollectMoney { int total; /** * Divide and conquer method to collect money from friends * * @param a amount to be distributed, preferably n=2^k * @return approximately the same amount a */ void dac(int a) { // recursive collect function if (a<=1) // if less than one Euro left total += a; // increase total amount else { dac(a/2); dac(a/2);} // recursive calls } int collect(int a) { total = 0; dac(a); return total; } }