cf B. Fox Dividing Cheese

http://codeforces.com/contest/371/problem/B

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 #define ll int
 6 using namespace std;
 7 
 8 ll a,b;
 9 int ans=0;
10 int m1,m2;
11 int check(ll x)
12 {
13     while(x)
14     {
15         if(x%2==0)
16         x/=2;
17         else if(x%3==0)
18         x/=3;
19         else if(x%5==0)
20         x/=5;
21         else
22         {
23            break;
24         }
25         ans++;
26     }
27     return x;
28 }
29 
30 ll gcd(ll c,ll d)
31 {
32     return d==0?c:gcd(d,c%d);
33 }
34 
35 int main()
36 {
37     cin>>a>>b;
38     if(a==b)
39     {
40         printf("0\n");
41         return 0;
42     }
43     int s=gcd(a,b);
44     a/=s;
45     b/=s;
46     if(check(a)==check(b))
47     {
48         printf("%d\n",ans);
49     }
50     else printf("-1\n");
51     return 0;
52 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3984952.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值