NC231122. Strange_Fractions
描述
输入描述
The first line contains one integer , denoting the number of test cases.
For each test case:
Input one line containing two integers , denoting the given fraction.
输出描述
For each test case:
If solution exists, output one line containing two integers , or print two zeros in one line if no solution.
示例1
输入:
2 5 2 5 1
输出:
1 2 0 0
说明:
For the first case, holds. So one possible solution is .C++ 解法, 执行用时: 63ms, 内存消耗: 1784K, 提交时间: 2022-04-21 14:44:47
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int tt; cin>>tt; while(tt--){ int p,q; scanf("%d%d",&p,&q); ll d2=ll(p)*p-4*q*q; int d=0; d=sqrtl(d2); if(ll(d)*d!=d2)puts("0 0"); else printf("%d %d\n",p+d,2*q); } }