[CodeForces 1141A] Game 23
题目链接: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的更多相关文章
- Codeforces Global Round 23 D.Paths on the Tree(记忆化搜索)
https://codeforces.ml/contest/1746/problem/D 题目大意:一棵n节点有根树,根节点为1,分别有两个数组 s[i] 顶点 i 的魅力值 c[i] 覆盖顶点 i ...
- CodeForces 22、23部分题解
CodeForces 22A 找严格第二小的...注意只有一种情况,可以sort排序然后unique输出. int a[N]; int main() { int n; while(~scanf(&qu ...
- Codeforces Educational Round 23
A emmmmmmmmm B emmmmmmmmm C(套路) 题意: 给定n和s(n,s<=1e18),计算n以内有多少个数x满足(x-x的各个位置数字之和)>=s 分析: 容易想到如果 ...
- CodeForces 1141A
https://vjudge.net/problem/CodeForces-1141A #include <bits/stdc++.h> using namespace std; int ...
- Codeforces Global Round 23 A-D
比赛链接 A 题解 知识点:贪心,构造. 注意到有 \(1\) 就一定能构造. 时间复杂度 \(O(n)\) 空间复杂度 \(O(1)\) 代码 #include <bits/stdc++.h& ...
- Codeforces Round #547 (Div. 3) A.Game 23
链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- react ref获取dom对象
react文档 step = React.createRef(); // init <div ref={this.step}></div> // bind componentD ...
- 更改ORACLE归档路径及归档模式
更改ORACLE归档路径及归档模式 在ORACLE10g和11g版本,ORACLE默认的日志归档路径为闪回恢复区($ORACLE_BASE/flash_recovery_area).对于这个路径, ...
- openshift 配置 bitbucket 的webhook
参考 https://docs.openshift.org/latest/dev_guide/builds/triggering_builds.html oc set triggers bc < ...
- bat杂记 cmd
强制复制覆盖 copy f:\temp1.txt f:\temp2.txt /y 删除 del f:\temp1.txt 删除任务aa1 schtasks /Delete /TN aa1 /F cmd ...
- 使用docker容器运行MySQL数据库并持久化数据文件
1.下载mysql镜像 # docker pull mysql 2.启动mysql容器 # docker run -itd -v /data:/var/lib/mysql -p 33060:3306 ...
- [httpd][daily] 查看并修改httpd的最大fd打开个数limit
重要提示: 请直接阅读步骤(6),如果不生效,再回头阅读(1)-(5). 如题: 修改这个文件就行了:/etc/security/limits.conf 查看当前配置的方法: 1. 找到httpd的p ...
- 手机连接wamp网页
1.改变wamp的put online 状态 Right click Wampmanager -> WAMPSetting -> Menu Item: Online/Offline
- 深度学习基础(一)LeNet_Gradient-Based Learning Applied to Document Recognition
作者:Yann LeCun,Leon Botton, Yoshua Bengio,and Patrick Haffner 这篇论文内容较多,这里只对部分内容进行记录: 以下是对论文原文的翻译: 在传统 ...
- windows7,python3使用time.strftime()函数报ValueError: embedded null byte
windows7环境下,执行代码报ValueError: embedded null byte时,在原代码前面加一行代码:locale.setlocale(locale.LC_ALL,'en')即可解 ...
- AsyncHttpClient使用
github地址:AsyncHttpClient, API:API 1.X和2.X差别很大,我用的1.X中的最新版 1.9.39. 这是一个异步请求的工具,越简单越好,不喜欢再结合netty使用.As ...