题目链接 Fox Dividing Cheese

思路:求出两个数a和b的最大公约数g,然后求出a/g,b/g,分别记为c和d。

   然后考虑c和d,若c或d中存在不为2,3,5的质因子,则直接输出-1(根据题目要求)

计算出c = (2 ^ a2) * (3 ^ a3) * (5 ^ a5)      d = (2 ^ b2) * (3 ^ b3) * (5 ^ b5)

   那么答案就是a2 + a3 + a5 + b2 + b3 + b5

#include <bits/stdc++.h>

using namespace std;

int a, b;
int n, m, x;
int a2, a3, a5, b2, b3, b5; int gcd(int a, int b){
return b == ? a : gcd(b, a % b);
} int main(){ scanf("%d%d", &n, &m);
if (n == m){puts(""); return ;}
x = gcd(n, m); a = n / x, b = m / x;
while (a % == ) { a /= , ++a2;}
while (a % == ) { a /= , ++a3;}
while (a % == ) { a /= , ++a5;} while (b % == ) { b /= , ++b2;}
while (b % == ) { b /= , ++b3;}
while (b % == ) { b /= , ++b5;} if (a > || b > ){
puts("-1");
return ;
} printf("%d\n", a2 + a3 + a5 + b2 + b3 + b5);
return ; }

最新文章

  1. BZOJ 1060: [ZJOI2007]时态同步
  2. PS通过滤色实现简单的图片拼合
  3. 说下查询动作 Pivot
  4. Windows 7 下如何设置机器级别的DCOM权限
  5. G面经prepare: Reorder String to make duplicates not consecutive
  6. 【宋红康学习日记1】关于环境变量设置出现的问题——找不到或无法加载主类 java
  7. stdafx.h的作用以及原理
  8. 在ubuntu12.04下编译android4.1.2添加JNI层出现问题
  9. PLSQL 循环示例
  10. Cross Product
  11. pcommlite串口通讯库使用
  12. JS中的phototype JS的三种方法(类方法、对象方法、原型方法)
  13. 【Gradle】Gradle环境配置
  14. &quot;当前不会命中断点,没有与此行关联的可执行代码&quot;可能和&quot;断点位置不准确&quot;有关
  15. python学习 day014打卡 内置函数二&amp;递归函数
  16. python print 使用分隔符 或行尾符
  17. W1002 Symbol &#39;Create&#39; is specific to a platform
  18. dubbo实际应用中的完整的pom.xml
  19. 【Python】Python 微服务框架 nameko
  20. ubuntu16.04下ftp服务器的安装与配置

热门文章

  1. 51nod_1459 最短路 dijkstra 特调参数
  2. eeeeeeeeeee
  3. Nodejs-文件系统操作
  4. Neural Network
  5. 12、jQuery知识总结-2
  6. STL学习笔记4--set and multiset
  7. psql 工具详细使用介绍
  8. 计算几何-凸包-toleft test
  9. [oldboy-django][3作业汇总]登录,注册最终版
  10. 环境说明与HelloWorld