Codeforces Round #547 (Div. 3) A.Game 23
2024-10-20 09:22:46
链接: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;
}
最新文章
- Linux串口中的超时设置
- Maven学习(七)仓库
- noip2006 2^k进制数
- 设计模式——";simple Factory";
- SOLR (全文检索)
- 【20160924】GOCVHelper 图像增强部分(4)
- poj 1004 Financial Management
- nyoj 116 士兵杀敌(二)【线段树单点更新+求和】
- 让两个Div并排显示
- TensorFlow的Bazel构建文件结构
- uboot使用笔记
- [ZZ] 多领域视觉数据的转换、关联与自适应学习
- sql特殊语法
- 微信小程序开发需要注意的30个坑
- RPC原理
- 针对MyISAM锁表的解决方案
- InitComponent的使用
- iOS开发中断言的使用—NSAssert()
- javascript年月日日期筛选控件
- ccf-201809-2 买菜
热门文章
- 使用bat文件打开和关闭本地exe
- ArcGIS服务器的feature图层限制
- 【转】hibernate懒加载的问题,failed to lazily initialize a collection of role
- Objective-C学习之解析XML
- map的详细用法 (转
- BZOJ_2989_数列&;&;BZOJ_4170_极光_KDTree
- 如何找GitHub上热门的开源项目
- Flutter实战视频-移动电商-19.首页_火爆专区界面布局编写
- 1、webpack课程介绍
- iOS 一次上传多张图片, 并返回进度值