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

 

你可能感兴趣的:(div)