Slim chance time limit: 5000ms single point time: 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
The same good water, direct storage code;
AC Code:
#include <iostream>#include<cstdio>#include<map>#include<cmath>#include<cstring>#include<algorithm>using namespacestd;Long LongN,m;map<Long Long,int>MP,NP;Long LonggcdLong LongXLong Longy) { if(y==0)returnx; returnGCD (y,x%y);}intMain () {CIN>>n>>m; Long LongCnt=0, cmt=0, a=0; Long LongFn= (Long Long) sqrt (n) +1; Long LongFm= (Long Long) sqrt (m) +1; for(intI=1; i<=fn;i++) { if(n%i==0) { if(!Np[i]) {Np[i]=1; CNT++; } if(!np[n/i]) {np[n/i]=1; CNT++; } } } for(intI=1; i<=fm;i++) { if(m%i==0) { if(!Mp[i]) {Mp[i]=1; CMT++; if(Np[i]) {a++; } } if(!mp[m/i]) {mp[m/i]=1; CMT++; if(np[m/I]) {a++; } } } } Long LongANS=GCD (cnt*cmt,a); cout<<cnt*cmt/ans<<" "<<a/ans<<"\ n"; return 0;}
hihocoder-1284 Chance is slim (water problem)