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. [Songqw.Net 基础]WPF插件化中同步Style

    原文:[Songqw.Net 基础]WPF插件化中同步Style 版权声明:本文为博主原创文章,未经博主允许可以随意转载 https://blog.csdn.net/songqingwei1988/a ...

  2. 标准差standard deviation和标准错误standard error你能解释一下

    by:ysuncn(欢迎转载,请注明原创信息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根:而方差是随机变量期望的二次偏差 ...

  3. Emgu-WPF学习使用 - 颜色映射

    原文:Emgu-WPF学习使用 - 颜色映射 string sFile = ""; if (!String.IsNullOrEmpty(AppConstUtils.GDefault ...

  4. 在Windows系统上以C++打印出当前活动用户的环境变量

    在Windows系统上以C++打印出当前活动用户的环境变量,代码如下(QT环境): void getEnvironmentVariables() { DWORD sessionId = WTSGetA ...

  5. 基于IdentityServer4的单点登录——Api

    1.新建项目并添加引用 新建一个asp .net core 2.0的项目引用IdentityServer4.AccessTokenValidation 2.配置 将Api与IdentityServer ...

  6. Aspect Oriented Programming面向切面编程

    I简介 Aspect Oriented Programming(AOP),面向切面编程,是一个比较热门的话题.AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或 ...

  7. SQL Server 阻止组件 xp_cmdshell

    错误信息描述 消息 15281,级别 16,状态 1,过程 xp_cmdshell,第 1 行SQL Server 阻止了对组件 'xp_cmdshell' 的 过程 'sys.xp_cmdshell ...

  8. JavaScript eval() 函数,计算某个字符串,并执行其中的的 JavaScript 代码。

    JavaScript eval() 函数,计算某个字符串,并执行其中的的 JavaScript 代码. 适合用于计算器的计算,等. 例子: eval("x=10;y=20;document. ...

  9. Android零基础入门第7节:搞定Android模拟器,开启甜蜜之旅

    原文:Android零基础入门第7节:搞定Android模拟器,开启甜蜜之旅 在前几期中总结分享了Android的前世今生.Android 系统架构和应用组件那些事.带你一起来聊一聊Android开发 ...

  10. 数据库连接池之_Druid简单使用

    数据库连接池: 连接池是创建和管理一个连接的缓冲池的技术,这些连接真备好被任何需要他们的线程使用,可以对传统的JDBCjava数据库连接()进行优化 在实际开发中,我们需要频繁的操作数据库,这就意味着 ...