题目链接:http://codeforces.com/problemset/problem/1141/A

首先,nn一定要是mm的倍数。否则就无法转换,输出-1;

然后令k=.\frac{m}{n} ,即k=.\frac{m}{n} .

将k 分解质因数,若分解结果是k=.\frac{m}{n} ,那答案就是k=.\frac{m}{n} 。

如果无法分解成k=.\frac{m}{n} ,那么输出-1。

AC代码:

#include <cstdio>

using namespace std;

int main() {
int n,m;
while(scanf("%d%d",&n,&m) != EOF) {
if(m % n != 0) {
puts("-1\n");
} else if (n == m) {
puts("0\n");
} else {
int k = m / n;
int cnt = 0;
while (k % 2 == 0) {
cnt++;
k /= 2;
}
while (k % 3 == 0) {
cnt++;
k /= 3;
}
if(k != 1) {
puts("-1\n");
} else {
printf("%d\n",cnt);
}
}
}
return 0;
}

[CodeForces 1141A] Game 23的更多相关文章

  1. Codeforces Global Round 23 D.Paths on the Tree(记忆化搜索)

    https://codeforces.ml/contest/1746/problem/D 题目大意:一棵n节点有根树,根节点为1,分别有两个数组 s[i] 顶点 i 的魅力值 c[i] 覆盖顶点 i ...

  2. CodeForces 22、23部分题解

    CodeForces 22A 找严格第二小的...注意只有一种情况,可以sort排序然后unique输出. int a[N]; int main() { int n; while(~scanf(&qu ...

  3. Codeforces Educational Round 23

    A emmmmmmmmm B emmmmmmmmm C(套路) 题意: 给定n和s(n,s<=1e18),计算n以内有多少个数x满足(x-x的各个位置数字之和)>=s 分析: 容易想到如果 ...

  4. CodeForces 1141A

    https://vjudge.net/problem/CodeForces-1141A #include <bits/stdc++.h> using namespace std; int ...

  5. Codeforces Global Round 23 A-D

    比赛链接 A 题解 知识点:贪心,构造. 注意到有 \(1\) 就一定能构造. 时间复杂度 \(O(n)\) 空间复杂度 \(O(1)\) 代码 #include <bits/stdc++.h& ...

  6. Codeforces Round #547 (Div. 3) A.Game 23

    链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...

  7. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 让height: 100%生效

    html: <body> <div class="box"></div> </body> css: .box{ position: ...

  2. java的Io流学习

    Java中io流的学习(一)File:https://blog.csdn.net/qq_41061437/article/details/81672859 Java中io流的学习(二)FileInpu ...

  3. CF3A Shortest path of the king

    The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...

  4. python os module

    os 模块提供了非常丰富的方法用来处理文件和目录.常用的方法如下表所示: 序号                                                              ...

  5. Winscp 密钥登录

    继前段时间,使用密钥SSH登录系统以后运维用着很爽,但是有一部分开发的同事反应使用Winscp添加私钥的时候,提示添加失败,原来Winscp使用的是putty作为SSH登录工具,而puttygen所生 ...

  6. super方法 调用父类的方法

    描述 super() 函数是用于调用父类(超类)的一个方法. super 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果使用多继承,会涉及到查找顺序(MRO).重复 ...

  7. 有多个正整数存放在数组中,编写一个函数要求偶数在左边由小到大顺序放置,奇数在右边,也是由小到大顺序放置,Java实现

    思路: * 1.首先分左右 * 2.分好再排序(左边和右边都单独排序) 第一步:分左右 可得注意了: 大体思路最先是从两头出发分成4种情况讨论(左or右,奇数or偶数)循环处理,出口是双层的嵌套循环( ...

  8. 逆向工程之修改关键CALL返回值_破解视频转换专家

    1)注册软件随便输入注册名注册码 2)进入软件根目录,发送到PEID查壳 3)发现无壳 4)发送到OD 4.1)右键菜单选择智能搜索 4.2)找到关键信息点注册 4.3)找到关键信息点双击进入汇编,向 ...

  9. awt多线程聊天

    public class ChatServer { boolean started = false; ServerSocket serverSocket = null; public void sta ...

  10. JS — 获取4个不重复的随机验证码

    var strCode='zxcvbnmasdfghjklopiuytrewqAWEDRFTGYHUJIK'; var str=''; for(var i=0;i<4;i++){ var ran ...