【题目链接】:http://hihocoder.com/contest/hiho144/problem/1
【题意】
【题解】
找出两个数相同的因子的个数x
然后两个数各自的因子的个数numa,nub;
x/(numa*numb)就是答案了;
统计相同因子个数的时候可以用个map;
因子个数不会像你想得那么多的;
很少的。
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;
LL n, m,numa,numb,ya,yb;
map <LL, int> dic;
LL gcd(LL a, LL b){
if (b == 0) return a;else return gcd(b, a%b);
}
int main(){
//freopen("F:\rush.txt", "r", stdin);
rel(n), rel(m);
LL i,len = sqrt(n);
for (i = 1; i <= len; i++)
if (n%i == 0){
if (i*i == n) ya++; else ya += 2;
dic[i] = dic[n / i] = 1;
}
len = sqrt(m);
for (i = 1;i <= len;i++)
if (m%i == 0){
if (i*i == m)
numa += dic[i],yb++;
else
numa += dic[i] + dic[m / i],yb+=2;
}
numb = ya*yb;
LL t = gcd(numa, numb);
numa /= t, numb /= t;
printf("%lld %lld
", numb, numa);
//printf("
%.2lf sec
", (double)clock() / CLOCKS_PER_SEC);
return 0;
}