Scalar Product

시간 제한3초메모리 제한1024 MB

요약
정수 벡터 (a,b)와 반지름 R이 주어질 때, x^2 + y^2 <= R^2인 정수점 (x,y)에서 a*x + b*y의 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
수학, 정수론, 기하, 이분 탐색
정답자
아직 제출이 없습니다

문제

Given vector (a,b)(a,b) (where aa and bb are integers) and integer RR. Find the maximum value of the scalar product (a,b)⋅(x,y)(a,b) \cdot (x,y), where both xx and yy are integer, and x2+y2≤R2x^2+y^2 \le R^2.

입력

First line of the input contains one integer TT --- the number of the test cases (1≤T≤1,0001 \le T \le 1\\,000). Each of the following TT lines contains three integers aa, bb and RR (−109≤a,b≤109-10^9 \le a,b \le 10^9, 1≤R≤1091 \le R \le 10^9).

출력

For each test case, print in the separate string one integer --- the maximal scalar product.

힌트

For the first test case in the sample, we have 13 integer points (x,y)(x,y) such as x2+y2≤R2x^2+y^2 \le R^2. Between those 13 points we have three points (2,0)(2,0), (1,−1)(1,-1), (0,−2)(0,-2) with the scalar prodct on (10,−10)(10,-10) reaches the maximum, for example, 10×1+(−10)×(−1)=2010 \times 1 + (-10) \times (-1) = 20.

예제1

  1. 예제 1

    입력
    3
    10 -10 2
    2 3 3
    5 1 3
    
    예상 출력
    20
    10
    15