Codeforces Round #116 Problem F Mathematical Analysis Rocks!