A. Divide it!

题目链接:http://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.

Input

The first line of the input contains one integer q
(1≤q≤1000) — the number of queries.

The next q
lines contain the queries. For each query you are given the integer number n (1≤n≤1018).
Output

Print the answer for each query on a new line. If it is impossible to obtain 1
from n , print -1. Otherwise, print the minimum number of moves required to do it.
Example
Input
Copy

7
1
10
25
30
14
27
1000000000000000000

Output

0
4
6
6
-1
6
72

题意

给你一个数n,如果能整除2,则n变成n/2;如果能整除3,则n变成(2/3)*n;如果能整除5,则变成(4/5)*n;

如果n能经过上述任意操作使n达到1,输出操作步数最小值,如果得不到1,输出-1.

思路

经过推算,

一个数如果能被2整除,那么可以先一直乘以1/2,

能够整除3的可以再一直乘以2/3,

能够整除5的可以再一直乘4/5,

和既能先乘以1/2的再乘2/3的再乘1/2的步数相同,所以代码就好实现了。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+; int main()
{ int n;
cin>>n;
ll x;
for(int i=;i<n;i++)
{ cin>>x;
if(x==)
puts("");
else
{
ll sum=;
bool flag=true;
while() {
if ((x / ) * == x) {
while ((x / ) * == x) {
// cout<<"2fff";
x = x / ;
// cout<<x;
sum++;
}
}
else if ((x / ) * == x) {
while ((x / ) * == x) {
x = (x * ) / ;
sum++;
}
}
else if ((x / ) * == x) {
while ((x / ) * == x) {
x = (x * ) / ;
sum++;
}
}
else if(x==)
break;
else {
flag=false;
break;
}
} if(!flag)
cout<<"-1"<<endl;
else
cout<<sum<<endl; }
}
return ;
}

Codeforces Round #565 (Div. 3) A的更多相关文章

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

  2. Codeforces Round #565 (Div. 3) A. Divide it!

    链接: https://codeforces.com/contest/1176/problem/A 题意: You are given an integer n. You can perform an ...

  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 #565 (Div. 3)

    传送门 A. Divide it! •题意 给定一个数n, 每次可以进行下列一种操作 1.如果n可以被2整除,用n/2代替n 2.如果n可以被3整除,用2n/3代替n 3.如果n可以被5整除,用4n/ ...

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

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

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

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. 【狼窝乀野狼】Windows Server 2008 R 配置 Microsoft Server 2008 远程登录连接

    如果你已经了解了,或者你已经经历了,那么此篇文章对你是毫无用处.因为文笔深处未必有自己亲身体验来的真实有效. 闲话少说,直接上菜. 最近脑子“抽筋”,想安装一个服务器来玩玩,那么怎么选择呢?我的PC是 ...

  2. 键盘各键对应的编码值(key code)

    原文:键盘各键对应的编码值(key code) 来源:http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes ...

  3. Eclipseproject标准的文件夹层次

    为什么特别写一个文档首场讲座解释什么层次,你是eclipse正在使用java.io.File类在读workspace档,我相信不知道eclipse,为了避免以后再出现这样的令人难堪的情况,还是编写这样 ...

  4. 隐藏system窗口你也行(就是那个cmd窗口,好多方法)

    新process的启动,可以通过system(const char*)函数启动另外一个程序,但是有一个小问题,就是每次执行system函数的时候,都会弹出dos窗口(命令行嘛~~~),有没有什么方法能 ...

  5. MS SQL SERVER搜索某个表的主键所在的列名

    原文:MS SQL SERVER搜索某个表的主键所在的列名 SELECT SYSCOLUMNS.name  FROM SYSCOLUMNS,SYSOBJECTS,SYSINDEXES,SYSINDEX ...

  6. Interactive Data Display如何显示菜单?

    貌似直接跟其它控件一样添加菜单就行了. 不过这个版本已经取消了默认菜单,所有的菜单功能都得自己去实现.

  7. Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar

    原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...

  8. webmethod基本认知

    六种控件统称flow step insert/invoke 插入services,类似调用函数 BRANCH 分支结构 参数名在switch定义 子参数以label确定 注意:确保label唯一,否则 ...

  9. 让您的应用兼容 Android Oreo

    不知不觉Android Oreo已经发布几个月时间了,你的应用开始使用最新平台了吗?在应用迁移过程中是否遇到了一些棘手问题?你的Android应用兼容Oreo如何呢? 我们应该都知道,每一次重大升级, ...

  10. .NET重思(二)接口和抽象类的取舍

    不得不说,接口和抽象类好像啊~两者都不可以实例化,并且未实现的部分都是由派生类实现的. 他们主要有这么个区别: (1)抽象类的派生类可以是派生类,换言之,抽象成员在派生类中不一定完全实现,而接口要求其 ...