题目链接:http://codeforces.com/gym/102021/
Problem E: Expired License
Paul is an extremely gifted computer scientist who just completed his master’s degree at a
prestigious German university. Now he would like to culminate his academic career in a PhD.
The problem is that there are so many great universities out there that it is hard for him to
pick the best. Because some application deadlines are coming up soon, Paul’s only way to
procrastinate his decision is by simply applying to all of them.
Most applications require Paul to attach a portrait photo. However, it seems like there does
not exist an international standard for the aspect ratio of these kinds of photos. While most
European universities ask Paul to send a photograph with aspect ratio 4.5 by 6, some Asian
countries discard the applications immediately if the photo does not have an aspect ratio of 7.14
by 11.22, precisely.
As Paul has never been interested in photo editing, he never had a reason to spend a lot of money
on proper software. He downloaded a free trial version some months ago, but that version
has already expired and now only works with some funny restrictions. The cropping tool, for
example, no longer accepts arbitrary numbers for setting the aspect ratio, but only primes. This
makes Paul wonder whether the desired aspect ratios can even be properly expressed by two
prime numbers. Of course, in case this is possible, he would also like to know the primes he has
to enter.
Input
The input consists of:
• one line with an integer n (1 ≤ n ≤ 105
), the number of applications Paul has to file;
• n lines, each with two real numbers a and b (0 < a, b < 100), where a × b is the desired
aspect ratio of one application.
All real numbers are given with at most 5 decimal places after the decimal point.
Output
For each application, if it is possible to represent the desired aspect ratio by two prime numbers
p and q, output one line with p and q. Otherwise, output impossible. If multiple solutions
exist, output the one minimizing p + q.
Sample Input 1 Sample Output 1
3
4.5 6
7.14 11.22
0.00002 0.00007
impossible
7 11
2 7
分析:
把所有数据改成ll 类型就过了,按理所不会超int型,o(╯□╰)o
对于x==y的情况,直接输出2 2
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e7 ;
const int M=1e4;
ll prime[M+1];
void init