You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
680 B
C++
33 lines
680 B
C++
#include <iostream>
|
|
#include <stack>
|
|
#include <cmath>
|
|
|
|
bool is_square(long long x) {
|
|
return (round(sqrt(x)) * round(sqrt(x))) == x;
|
|
}
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
int T;
|
|
std::cin >> T;
|
|
for (int i = 0; i < T; ++i)
|
|
{
|
|
long long X, Y;
|
|
long long D;
|
|
double Df;
|
|
std::cin >> D;
|
|
std::cin >> X;
|
|
std::cin >> Y;
|
|
|
|
if (!((X * X + Y * Y) % D) && is_square((X*X + Y*Y) / D)) {
|
|
std::cout << (long long)round((X*X + Y*Y) / D) << std::endl;
|
|
continue;
|
|
}
|
|
Df = sqrt(D);
|
|
long double ans = sqrt(((X * X) + (Y * Y))) / Df;
|
|
if ((long long)ceil(ans) == 1) ans = 2;
|
|
//if (ans != 0) ans -= 1e-6;
|
|
std::cout << (long long)ceil(ans) << std::endl;
|
|
}
|
|
return 0;
|
|
} |