/* -*- coding: utf-8 -*- * * 2953.cc: No.2953 Maximum Right Triangle - yukicoder */ #include #include using namespace std; /* constant */ /* typedef */ using ll = long long; /* global variables */ /* subroutines */ template T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } ll cross(int x0, int y0, int x1, int y1) { return (ll)x0 * y1 - (ll)x1 * y0; } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int d, ax, ay; scanf("%d%d%d", &d, &ax, &ay); // (bx,by) = (ax,ay)+(vy,-vx)t // 0<=bx<=d -> 0<=ax+vy*t<=d -> -ax<=vy*t<=d-ax -> -ax/vy<=t<=(d-ax)/vy // 0<=by<=d -> 0<=ay-vx*t<=d -> -ay<=-vx*t<=d-ay -> -(d-ay)/vx<=t<=ay/vx if (ax == 0 || ay == 0) printf("%lld\n", (ll)d * max(ax, ay)); else { // ax>0 && ay>0 int g = gcd(ax, ay); int vx = ax / g, vy = ay / g; int l = max(-(double)ax / vy, -(double)(d - ay) / vx); int r = min((double)(d - ax) / vy, (double)ay / vx); //printf(" l=%d, r=%d\n", l, r); int lbx = ax + vy * l, lby = ay - vx * l; int rbx = ax + vy * r, rby = ay - vx * r; ll s0 = abs(cross(ax, ay, lbx, lby)); ll s1 = abs(cross(ax, ay, rbx, rby)); printf("%lld\n", max(s0, s1)); } } return 0; }