Răspuns:
#include <fstream>
#include <cmath>
std::ifstream in("formula1.in");
std::ofstream out("formula1.out");
int main()
{
long long n, k, c, a, x;
in >> c >> k >> n;
if (c == 1)
out << (2 * k - 1) * (2 * k - 1);
else
{
a = (n * (n + 1) * (2 * n + 1)) / 3 - n * (n + 1);
x = (int)sqrt(2 * a + 1);
out << (x % 2 ? x * x : (x - 1) * (x - 1));
}
out.close();
}
Explicație: