hihocoder-1284 chances are slim (water problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.