Codeforces Round #547 (Div. 3) A.Game 23
链接: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的更多相关文章
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- 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 ...
- Codeforces Round #547 (Div. 3) G 贪心
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #547 (Div. 3) D
http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i ...
- Codeforces Round #547 (Div. 3) D. Colored Boots
链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...
- Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...
- Codeforces Round #547 (Div. 3)
我老人家走了四公里吃个汉堡还没吃成.垃圾肯德基.垃圾春分半价桶. 蜜雪冰城百香果加冰+烤串真是爽死了.原来二十多块钱可以吃的这么爽. A: #include <bits/stdc++.h> ...
- 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 ...
随机推荐
- 盒子的display属性
<body> <div style="display:inline">Box-1</div> <div style="displ ...
- vue路由的两种模式,hash与history
对于Vue 这类渐进式前端开发框架,为了构建SPA(单页面应用),需要引入前端路由系统,这也就是Vue-router存在的意义.前端路由的核心,就在于——— 改变视图的同时不会向后端发出请求. 一.为 ...
- chrome最小字体12px
http://www.mamicode.com/info-detail-512021.html http://www.divcss5.com/wenji/w738.shtml
- Codeforces Round #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )
B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...
- Good Bye 2015 B. New Year and Old Property —— dfs 数学
题目链接:http://codeforces.com/problemset/problem/611/B B. New Year and Old Property time limit per test ...
- c/c++通用内存泄漏检测框架GMFD(General Memory Fault Detection Framework)
http://qa.baidu.com/blog/?p=171 1 背景: x86平台有完善的用户态检测内存工具比如valgrind等,可以监控程序运行中详细的内存信息,从而精确定位内存问题.然而随着 ...
- Session移除
Session.Clear()就是把Session对象中的所有项目都删除了,Session对象里面啥都没有.但是Session对象还保留. Session.Abandon()就是把当前Session对 ...
- margin-top 为什么会影响父元素的 margin-top
1.原因: In this specification, the expression collapsing margins means that adjoining margins (no non ...
- nyoj 86 --位标记
nyoj 86 --位标记 点击打开题目链接 : 找球号(一) 这道题目很多解法,其他解法请参考 http://www.cnblogs.com/play ...
- hdu-4989 Summary(水题)
题目链接: Summary Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) P ...