链接:https://codeforces.com/contest/1141/problem/A

题意:

给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m。

不能得到时为-1。

思路:

先判断是否为整数倍。

再将倍数不断除以2和3。

最后剩下1则可以达到否则-1。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
int n, m;
cin >> n >> m;
if (m % n != 0)
cout << -1 << endl;
else
{
int cnt = 0;
int t = m / n;
while (t % 2 == 0)
t /= 2, cnt++;
while (t % 3 == 0)
t /= 3, cnt++;
if (t != 1)
cout << -1 << endl;
else
cout << cnt << endl;
} return 0;
}

  

最新文章

  1. Linux串口中的超时设置
  2. Maven学习(七)仓库
  3. noip2006 2^k进制数
  4. 设计模式——&quot;simple Factory&quot;
  5. SOLR (全文检索)
  6. 【20160924】GOCVHelper 图像增强部分(4)
  7. poj 1004 Financial Management
  8. nyoj 116 士兵杀敌(二)【线段树单点更新+求和】
  9. 让两个Div并排显示
  10. TensorFlow的Bazel构建文件结构
  11. uboot使用笔记
  12. [ZZ] 多领域视觉数据的转换、关联与自适应学习
  13. sql特殊语法
  14. 微信小程序开发需要注意的30个坑
  15. RPC原理
  16. 针对MyISAM锁表的解决方案
  17. InitComponent的使用
  18. iOS开发中断言的使用—NSAssert()
  19. javascript年月日日期筛选控件
  20. ccf-201809-2 买菜

热门文章

  1. 使用bat文件打开和关闭本地exe
  2. ArcGIS服务器的feature图层限制
  3. 【转】hibernate懒加载的问题,failed to lazily initialize a collection of role
  4. Objective-C学习之解析XML
  5. map的详细用法 (转
  6. BZOJ_2989_数列&amp;&amp;BZOJ_4170_极光_KDTree
  7. 如何找GitHub上热门的开源项目
  8. Flutter实战视频-移动电商-19.首页_火爆专区界面布局编写
  9. 1、webpack课程介绍
  10. iOS 一次上传多张图片, 并返回进度值