Codeforces Round #565 (Div. 3) A. Divide it!
链接:
https://codeforces.com/contest/1176/problem/A
题意:
You are given an integer n.
You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:
Replace n with n2 if n is divisible by 2;
Replace n with 2n3 if n is divisible by 3;
Replace n with 4n5 if n is divisible by 5.
For example, you can replace 30 with 15 using the first operation, with 20 using the second operation or with 24 using the third operation.
Your task is to find the minimum number of moves required to obtain 1 from n or say that it is impossible to do it.
You have to answer q independent queries.
思路:
优先操作2, 再3,再5.
暴力即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
LL n, m, k, t;
int main()
{
// freopen("test.in", "r", stdin);
cin >> t;
while (t--)
{
cin >> n;
int res = 0;
bool flag = true;
while (n != 1)
{
if (n%2 == 0)
n = n/2;
else if (n%3 == 0)
n = (n/3)*2;
else if (n%5 == 0)
n = (n/5)*4;
else
{
flag = false;
break;
}
res++;
}
if (flag)
cout << res << endl;
else
cout << -1 << endl;
}
return 0;
}
Codeforces Round #565 (Div. 3) A. Divide it!的更多相关文章
- Codeforces Round #565 (Div. 3) A
A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...
- Codeforces Round #565 (Div. 3) B. Merge it!
链接: https://codeforces.com/contest/1176/problem/B 题意: You are given an array a consisting of n integ ...
- Codeforces Round #565 (Div. 3) C. Lose it!
链接: https://codeforces.com/contest/1176/problem/C 题意: You are given an array a consisting of n integ ...
- Codeforces Round #565 (Div. 3) B
B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...
- Codeforces Round #565 (Div. 3) F.Destroy it!
题目地址:http://codeforces.com/contest/1176/problem/F 思路:其实就是一个01背包问题,只是添加了回合和每回合的01限制,和每当已用牌数到了10的倍数,那张 ...
- Codeforces Round #479 (Div. 3) D. Divide by three, multiply by two
传送门 D. Divide by three, multiply by two •题意 给你一个数 x,有以下两种操作,x 可以任选其中一种操作得到数 y 1.如果x可以被3整除,y=x/3 2.y= ...
- Codeforces Round #565 (Div. 3)
传送门 A. Divide it! •题意 给定一个数n, 每次可以进行下列一种操作 1.如果n可以被2整除,用n/2代替n 2.如果n可以被3整除,用2n/3代替n 3.如果n可以被5整除,用4n/ ...
- Codeforces Round #565 (Div. 3)--D. Recover it!--思维+欧拉筛
D. Recover it! Authors guessed an array aa consisting of nn integers; each integer is not less than ...
- Codeforces Round #565 (Div. 3) C. Lose it! (思维)
题意:给你一串只含\(4,8,15,16,23,42\)的序列,如果它满足长度是\(6\)的倍数并且有\(\frac {k}{6}\)个子序列是\([4,8,15,16,23,42]\),则定义它是好 ...
随机推荐
- html事件绑定总结以及window.onload和document.body.onload事件
//1 document.onkeydown如果多次监听同样的事件,那么前面的监听函数都会被最后一次的监听函数所覆盖. //如下所示: document.onkeydown = function(ev ...
- 使用Visual Studio进行单元测试-Part4
本文主要介绍Visual Studio(2012+)单元测试框架的一些技巧: 如何模拟类的构造函数 优化代码,便于测试 一.如何模拟类的构造函数 1.1 被测代码 基础代码,IShape分别有Rect ...
- HDU3018:Ant Trip(欧拉回路)
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 关于使用C# 启动msi失败的问题
原以为在启动msi是件小儿科的事,上代码: ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "C:\\myTest ...
- assert.equal()
assert.equal(actual, expected[, message]) 使用相等运算符(==)测试 actual 参数与 expected 参数是否相等(通俗解释equal方法接受三个参数 ...
- 通过sessionid提取这个用户在服务器中保存的session变量
- Entity Framework:Code-First Tutorial开篇
这个系列文章是关于Entity Framework Code-First的英文系列文章,内容不错,每篇一个主题知识点介绍,特转载过来 原文地址:http://www.entityframeworktu ...
- Struts2学习第三课 Struts2详解
接着上次的课程 这次我们看struts.xml 修改如下:这里是加上命名空间,默认的是不加,我们手动加上时就要在访问时加上命名空间. <?xml version="1.0" ...
- Linux包管理
1.yum(Yellow dog Updater, Modified) yum是一个在Fedora(基于Linux的操作系统)和RedHat(基于Linux的操作系统)以及SUSE(基于Linux的操 ...
- 【mysql远程连库】
mysql连接远程库: 服务器端: 1.登陆服务器端,进入命令行,windows cmd; 2.设置用户.密码让指定的IP访问:MySQL -u root -p 或安装的快捷方式进入:MySQL Co ...