链接: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;
}

  

Codeforces Round #547 (Div. 3) A.Game 23的更多相关文章

  1. Codeforces Round #547 (Div. 3) 题解

    Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...

  2. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #547 (Div. 3) G 贪心

    https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...

  4. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  5. Codeforces Round #547 (Div. 3) D

    http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i ...

  6. Codeforces Round #547 (Div. 3) D. Colored Boots

    链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...

  7. Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest

    链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...

  8. Codeforces Round #547 (Div. 3)

    我老人家走了四公里吃个汉堡还没吃成.垃圾肯德基.垃圾春分半价桶. 蜜雪冰城百香果加冰+烤串真是爽死了.原来二十多块钱可以吃的这么爽. A: #include <bits/stdc++.h> ...

  9. Codeforces Round #547 (Div. 3) E. Superhero Battle

    E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which ...

随机推荐

  1. 避免复杂的layout

    layout是浏览器计算元素的几何信息:元素在页面上的的大小和位置. 每个元素都有明确的亦或含蓄的大小信息,这些信息基于我们使用的css以及元素的内容被高和父亲元素. 这个过程在 Chrome, Op ...

  2. Spring MVC 注解开发详解

    @Controller控制器定义 1.Controller是单利模式,被多个线程请求共享,因此设计成无序状态. 2.通过@controller标注即可将class定义为一个controller类.为使 ...

  3. Java面向对象的三大特征详解

    一.封装(Encapsulation)       封装也称信息隐藏,是指利用抽象数据类型把数据和基于数据的操作封装起来,使其成为一个不可分割的整体,数据隐藏在抽象数据内部,尽可能的隐藏数据细节,只保 ...

  4. UVA-10534 (LIS)

    题意: 给定一个长为n的序列,求一个最长子序列,使得该序列的长度为2*k+1,前k+1个数严格递增,后k+1个数严格单调递减; 思路: 可以先求该序列最长单调递增和方向单调递增的最长序列,然后枚举那第 ...

  5. codeforces 669A A. Little Artem and Presents(水题)

    题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. smali语法积累记录

    1.constructor 我们知道运行一个类的时候会先调用static方法中的内容,比如: static { System.loadLibrary("qihooTest"); } ...

  7. poj3070 求斐波那契数列第n项 ——矩阵快速幂

    题目:http://poj.org/problem?id=3070 用矩阵快速幂加速递推. 代码如下: #include<iostream> #include<cstdio> ...

  8. APIO2015巴厘岛的雕塑——数位DP

    题目:https://www.luogu.org/problemnew/show/P3646 对于A>1,将答案各位全置1,然后从高位到低位改成0判断是否可行: 用f[i][j]数组代表前i个数 ...

  9. Day03:集合、文件处理和函数基础

    上节课复习:    1.总结        可变/不可变:            可变类型:list,dict            不可变类型:int,float,str,tuple         ...

  10. 小程序wx:key中的关键字*this

    “保留关键字 *this 代表在 for 循环中的 item 本身,这种表示需要 item 本身是一个唯一的字符串或者数字,如果是对象则不可以 data:{ array:[1,2,3,4,5], ob ...