How can I get the cost of this function? I know it is O(√n) but other than trying a lot of n values and getting a pattern I don't know how to find it.
void foo(int n) {
int x = 2;
int y = 1;
while(y <= n) {
y += x;
++x;
}
}