Gym - 102021E

Gym - 102021E
https://vjudge.net/problem/2109787/origin
主要是一个处理精度的技巧,避免精度误差可以加eps,然后乘1e(小数点之后的位数)。

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 10000010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()

using namespace std;
int T;
double x,y,t;
int a,b;
int n,cnt;
int prime[N];
bool vis[N];

void in(int &x){
    int y=1;
    char c=g();x=0;
    while(c<'0'||c>'9'){
        if(c=='-')y=-1;
        c=g();
    }
    while(c<='9'&&c>='0'){
        x=(x<<1)+(x<<3)+c-'0';c=g();
    }
    x*=y;
}
void o(int x){
    if(x<0){
        p('-');
        x=-x;
    }
    if(x>9)o(x/10);
    p(x%10+'0');
}

void Euler(){
    vis[1]=1;
    For(i,2,10000000){
        if(!vis[i]) prime[++cnt]=i;
        for(int j=1;j<=cnt&&i*prime[j]<=10000000;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)
                break;
        }
    }
}

int gcd(int a,int b){
    return (a%b==0?b:gcd(b,a%b));
}

int main(){
    in(T);
    Euler();
    while(T--){
        cin>>x>>y;
        a=(int)((x+1e-7)*1e5);
        b=(int)((y+1e-7)*1e5);
        t=gcd(a,b);
        a/=t;
        b/=t;
        if(a==b){
            cout<<"2 2"<<endl;
            continue;
        }
        if(!vis[a]&&!vis[b])
            cout<<a<<" "<<b<<endl;
        else
            cout<<"impossible"<<endl;
    }
    return 0;
}

 

posted @ 2019-07-20 15:07  WeiAR  阅读(173)  评论(0编辑  收藏  举报