链接:

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!的更多相关文章

  1. Codeforces Round #565 (Div. 3) A

    A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #565 (Div. 3) B

    B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...

  5. Codeforces Round #565 (Div. 3) F.Destroy it!

    题目地址:http://codeforces.com/contest/1176/problem/F 思路:其实就是一个01背包问题,只是添加了回合和每回合的01限制,和每当已用牌数到了10的倍数,那张 ...

  6. 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= ...

  7. 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/ ...

  8. 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 ...

  9. Codeforces Round #565 (Div. 3) C. Lose it! (思维)

    题意:给你一串只含\(4,8,15,16,23,42\)的序列,如果它满足长度是\(6\)的倍数并且有\(\frac {k}{6}\)个子序列是\([4,8,15,16,23,42]\),则定义它是好 ...

随机推荐

  1. NYOJ-115 Dijlstra

    原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=115 #include"iostream" #include" ...

  2. 使用Visual Studio进行单元测试-Part3

    本文主要介绍Visual Studio(2012+)单元测试框架的一些技巧: 测试覆盖率的统计 测试分组 测试Setup/TearDown 测试调试 Exception测试 代码覆盖率的统计 VS下面 ...

  3. [转] 更新Flash CS6发布设置的目标播放器版本

    目前Aodbe发布的最新版的Flash CS6,都不支持将Flash Player 11作为目标播放器版本发布.这个问题很容易解决,但涉及到的东西却比较多,我在这里将一一讲解.首先来个Setp by ...

  4. JINKENS

    https://www.cnblogs.com/ceshisanren/p/5639869.html

  5. 人物-IT-刘强东:刘强东

    ylbtech-人物-IT-刘强东:刘强东 刘强东,男,汉族,1973年3月10日生(另一说法:1974年2月14日),江苏宿迁人,祖籍湖南湘潭 .京东集团董事局主席兼首席执行官,本科毕业于中国人民大 ...

  6. jQuery对象和DOM对象的互换

    Dom 对象:指的是普通的 JavaScript 对象 jQuery对象:是包装 Dom 对象后产生的对象. 一:JQuery 对象和 Dom 对象 在使用 JQuery 过程中,我们一般(也是绝大多 ...

  7. sql查询将列里面的值替换为别的值但是实际值不变

    数据库有一张表BUG(缺陷记录表) 里面有字段severity(严重程度): severity的值实际为1,2,3,4,但希望在查询结果中将severity的1,2,3,4值显示为其他的值,但seve ...

  8. 6.JasperReports学习笔记6-jasperreports和ssh工程整合

    转自:http://www.blogjava.net/vjame/archive/2013/10/12/404908.html 一.导入jasperreport相关jar包,这里采用当前比较稳定的5. ...

  9. Windchill 配置LOG文件,使开发中的代码能显示打印的信息

    如开发代码的类HomeLogic.java, 包路径在pnt.report.home 需求:需监控此类的打印数据 方法:配置D:\ptc\Windchill_10.1\Windchill\codeba ...

  10. nodejs中 underscore 包有什么作用

    Underscore一个JavaScript实用库,提供了一整套函数式变成有用的实用功能,但是没有扩展任何JavaScript内置对象.它是这个问题的答案:“如果我在一个空白的HTML页面前坐下, 并 ...