链接:

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. Metasploit的使用下篇——漏洞攻击

    一.上文总结 上篇当中主要通过开启的端口对目标主机进行攻击,最后成功做到了连接不过却不能查看到telnet的登陆用户名和密码,目前来看有两个原因:第一.我对于靶机telnet的设置有问题,没有设置相应 ...

  2. 如何恢复,迁移,添加, 删除 Voting Disks

    如何恢复,迁移,添加, 删除 Voting Disks恢复流程 在11gR2 之前,我们可以直接直接使用dd命令对voting disk进行备份.DD示例 备份votedisk盘:[root@raw1 ...

  3. JZOJ 1003【东莞市选2007】拦截导弹——dp

    题目:https://jzoj.net/senior/#main/show/1003 只要倒推一下第一次上升的最长和第一次下降的最长就行了.不用n^2logn,枚举了 j 还要用树状数组找值比自己大的 ...

  4. VS2008中宽字节和普通字节的使用

    由于麻烦,所以并没有使用宽字节,留待以后.

  5. Poj 1659 Distance on Chessboard(国际象棋的走子规则)

    一.Description 国际象棋的棋盘是黑白相间的8 * 8的方格,棋子放在格子中间.如下图所示: 王.后.车.象的走子规则如下: 王:横.直.斜都可以走,但每步限走一格. 后:横.直.斜都可以走 ...

  6. UE3代码阅读需知

    转自:http://www.cnblogs.com/hmxp8/archive/2012/02/21/2361211.html 掌握一款庞大的引擎,要一下子掌握真的很难,慢慢地从Editor,Scri ...

  7. java报表开发之报表总述

    转自:https://blog.csdn.net/u011659172/article/details/40504271?utm_source=blogxgwz6

  8. linux日常管理-系统服务

    开机不启动不必要系统服务,节省硬件资源,解决安全隐患 调整服务有两种办法 没有这个命令就安装一下.执行这个命令,出现下面界面 按空格键选择或取消,tab切换选择确定或取消 系统服务留下 crond i ...

  9. ORACLE AWR报告生成步骤

    ORACLE AWR报告生成步骤 (以PL/SQL中命令窗口为例) 1.sqlplus或plsql的commod窗口(命令窗口)运行命令 @D:\oracle\product\10.2.0\db_1\ ...

  10. 使用showConfirmDialog显示确认框

    ------------------siwuxie095                                 工程名:TestJOptionPane 包名:com.siwuxie095.s ...