In this problem (
[192A Funky Numbers](https://codeforces.com/contest/192/problem/A)), given an integer 'n', find if it can be the sum of two triangular numbers where a triangular number equals k(k+1)/2 for some positive integer k.
I have two questions regarding this problem.
In many solutions I saw, people would increment and int i from i to Math.sqrt(n) and use this value to find the k value for the second triangular number by using the equation n — (i(i+1)/2). Why stop at Math.sqrt(n)?
Following the above algorithm, k2 (the k of the second triangular number) could be found as such:
int k2 = (int)(Math.sqrt((n — (i*(i+1)/2)) * 2));
This time, why is Math.sqrt() used, and why is the result multiplied by 2?
Thank you for your help, Codeforces community.