Gym - 102021E: Expired License
meaning of the questions: give you a pair of floating-point numbers, which allow you to determine the ratio of floating point numbers can use the ratio of one pair of prime numbers represented, if it can output two prime numbers.
Analysis: First, to convert the string to the digital process (double data converted to vary int), the first two numbers unified into an integer multiplied by 10 ^ 6, and then divided by two in the number of their greatest common divisor is determined whether or not a prime number . Wherein which contains a special case is when the two numbers are equal, the output of the direct 2,2
#include<iostream> #include<string.h> #include<string> #include<algorithm> #include<math.h> #include<string> #include<string.h> #include<vector> #include<utility> #include<map> #include<queue> #include<set> #define mx 0x3f3f3f3f #define ll long long using namespace std; const int maxn = 1e7 + 10 ; int Prim [MAXN], W [MAXN], CNT = 0 ; // Prim [i] plays as a marker, prim [i] == 0 i is a prime number indicates int X [MAXN]; // X [i] represents an even number is the number of two mass qualified i is x [i] and IX [i]; void the init () { Memset (Prim, 0 , the sizeof (Prim)); for ( int i = 2 ; i <MAXN; ++ i ) { iF (Prim [i]) // determines whether or not i is an even number Continue ; W [CNT ++] = i; // W deposit prime for ( int J = i << . 1; J <MAXN; = J + I) // to all multiples of prime numbers marked Prim [J] = . 1 ; } } LL GCD (A LL, LL B) // common divisor { return B == 0 A:? GCD (B, A% B); } String S1, S2; int main () { int T; CIN >> T; the init (); Prim [ . 1 ] = . 1 ; the while (T-- ) { LL K1 = 0 , K2 = 0 , = POS1 . 6 , POS2 =6;//先默认乘以10^6 cin>>s1>>s2; int len1=s1.length(); int len2=s2.length(); for(int i=0;s1[i];i++) { if(s1[i]!='.') k1=k1*10+(s1[i]-'0'); else pos1=len1-i-1; } for(int i=0;s2[i];i++) { if(s2[i]!='.') k2=k2*10+(s2[i]-'0'); else pos2=len2-i-1; } while(pos1) { k1=k1*10; pos1--; } while(pos2) { k2=k2*10; pos2--; } if(k1==k2) { cout<<2<<' '<<2<<endl; continue; } ll temp=gcd(k1,k2); k1=k1/temp; k2=k2/temp; if(prim[k1]==0&&prim[k2]==0) cout<<k1<<' '<<k2<<endl; else cout<<"impossible"<<endl; } return 0; }