#include // Three different functions, all pretty basic // A - add up all the numbers in a particular range // first method: find the sum of the rest of the range, and just add the first to it. int addupa(const int start, const int end) { // special case, only one number if (start == end) return start; // what is 1+2+3+4+5+6+7 ? // what is 2+3+4+5+6+7? add one to that // general pattern const int rest = addupa(start + 1, end); return start + rest; } // B - add up all the numbers in a particular range // second method: split the range in half. Find the sums of the two halves, and add them int addupb(const int start, const int end) { // special case, only one number if (start == end) return start; // what is 1+2+3+4+5+6+7 ? // what is 1+2+3+4 // what is 5+6+7 // add them for the answer // general pattern const int middle = (start + end) / 2; const int first_half = addupb(start, middle); const int second_half = addupb(middle + 1, end); return first_half + second_half; } // C - find the sum of all the values of 3*i*i over a given range // pretty much the same as A really. int addupc(const int start, const int end) { // sum of 3 i squared for a going from start to end if (start == end) return 3*start*start; const int rest = addupc(start + 1, end); return 3*start*start + rest; } void main() { const int a = read_int(); const int b = read_int(); print(addupc(a, b)); new_line(); }