#1284: Opportunity Slim time limit: 5000ms single point limit: 1000ms memory limit: 256MB description
Small hi recently in pursuit of a math girl little Z. Small z is actually want to reject him, but can not find good rhetoric, so put forward the request: for a given two positive integers n and m, small hi randomly selected an n ' approximate n ', small z randomly selected a m's approximate m ', if n ' and M ' equal, she promised small hi.
Small z let small hi to write this random program, then she review had no problem, you can draw the lottery. But small hi wrote, but more and more feel the opportunity is slim. So the question is, what is the odds that little hi can catch a little z?
Input
Each input file contains only a single set of test data.
The first behavior of each set of test data is two positive integers n and M, meaning as described earlier.
For 40% of data, meet 1<=n,m<=106
For 100% of data, meet 1<=n,m<=1012
Output
For each set of test data, the output of two coprime positive integers A and B (with a per B indicates the chance that small hi can catch small z).
-
-
Sample input
-
-
3 2
-
-
Sample output
-
4 1
Hint: f[i] is used to mark I as an approximate of N, m/i is also approximate. Then, when traversing m approximate, if f[i] exists, that is, I is n,m public approximate. Finally need to request greatest common divisor,-pass.
AC Code:
1#include"iostream"2#include"math.h"3#include"Map"4 #defineMAX 10000005 6 using namespacestd;7typedefLong LongLL;8 9 LL N, m;TenMap<ll,int>F; One A ll GCD (ll A, ll b) - { - if(b = =0) the returnA; - Else - returnGCD (b, a%b); - } + - + intMain () A { atCIN >> N >>m; -LL p =0, q =0, r =0 ; - LL Gcdnum; - - for(LL i =1; I*i <= N; i++){ - if(n% i = =0) in { -F[i] =1; toF[N/I] =1; +p++; - if(I! = N/i) theP + +; * } $ }Panax Notoginseng - for(LL i =1; I*i <= m; i++){ the if(m% i = =0) + { Aq++; the if(F[i]) +r++; - $ if(I! = m/i) $ { -q++; - if(F[m/i]) ther++; - }Wuyi } the } - WuGcdnum = gcd (p*Q, R); - Aboutcout << P*q/gcdnum <<" "<< R/Gcdnum; $ -}
Hiho #1284 a slim chance