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 ...
随机推荐
- LwIP移植uCos+stm32f407
LwIP同操作系统一起工作的时候模型如下: 1.TCP/IP协议栈和应用程序以分离的任务运行 2.应用同协议栈沟通是通过API函数调用(API函数调用事实上就是通过OS自带的进程间通信机制,由应用程序 ...
- 在springboot中使用Mybatis Generator的两种方式
介绍 Mybatis Generator(MBG)是Mybatis的一个代码生成工具.MBG解决了对数据库操作有最大影响的一些CRUD操作,很大程度上提升开发效率.如果需要联合查询仍然需要手写sql. ...
- Android 6.0 如何默认打开user版本的root权限【转】
本文转载自:http://blog.csdn.net/wangjicong_215/article/details/77601638 1.system/core/adb/Android.mkdiff ...
- HTML5 <template>
http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/
- 第二篇:python基础之核心风格
阅读目录 一.语句和语法 二.变量定义与赋值 三.内存管理 内存管理: 引用计数: 简单例子 四.python对象 五.标识符 六.专用下划线标识符 七.编写模块基本风格 八.示范 一.语句和语法 # ...
- CodeForces526F:Pudding Monsters (分治)
In this problem you will meet the simplified model of game Pudding Monsters. An important process in ...
- python 文件与文件夹常见操作以及os.walk的用法
文件操作: In [34]: import os In [35]: os.rename("hello[复件].py","hello111.py") ...
- C++之PIMPL模式
1 PIMPL解释 PIMPL(Private Implementation 或 Pointer to Implementation)是通过一个私有的成员指针,将指针所指向的类的内部实现数据进行隐藏. ...
- bzoj 4668 冷战——并查集结构
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4668 不路径压缩,维护并查集的树的结构,查询链上最大值.按秩合并就可以暴爬. #includ ...
- 十五、事务(Transaction)
1.事务是什么? 2.示例 查询事务的隔离级别, 1>会话级(select @@tx_isolation或select @@session.tx_isolation) 2>全局级(sele ...