Divide it!

You are given an integer nn.

You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:

  1. Replace nn with n2n2 if nn is divisible by 22;
  2. Replace nn with 2n32n3 if nn is divisible by 33;
  3. Replace nn with 4n54n5 if nn is divisible by 55.

For example, you can replace 3030 with 1515 using the first operation, with 2020 using the second operation or with 2424 using the third operation.

Your task is to find the minimum number of moves required to obtain 11 from nn or say that it is impossible to do it.

You have to answer qq independent queries.

Input

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

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

Output

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

代码:

 #include<iostream>
#include<algorithm>
using namespace std;
int main() {
int q;
long long a[];
cin>>q;
for(int i=; i<q; i++) {
cin>>a[i];
}
for(int q1=;q1<q;q1++){
int cnt=;
while(a[q1]!=) {
if(a[q1]%!=&&a[q1]%!=&&a[q1]%!=){
cnt=-;
break;
}
if(a[q1]%==) {
a[q1]/=;
cnt++;
}
if(a[q1]%==) {
a[q1]=a[q1]*/;
cnt++;
}
if(a[q1]%==) {
a[q1]=a[q1]*/;
cnt++;
}
if(a[q1]==){
break;
}
}
cout<<cnt<<endl;
}
}

思路分析:数要是不能被3,5,2整除,就设置cnt为-1并输出。先除2/n再2n/3z再4n/5统计次数,最后化为1,输出cnt。

链接:https://codeforces.com/problemset/problem/1176/A

Codeforces1176A(A题)Divide it!的更多相关文章

  1. leetcode第28题--Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 分析:题目意思很容易理解,就是不用乘除法和模运 ...

  2. java中的位操作

    之前做项目的时候使用位操作不是很多,今天在刷leetcode上题目的时候用到了位操作,是leetcode中的第29题Divide Two Integers. 一.java的位操作: 位运算表达式由操作 ...

  3. 【LeetCode每天一题】Divide Two Integers(两整数相除)

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

  4. LeetCode第[29]题(Java):Divide Two Integers

    题目:两整数相除 难度:Medium 题目内容: Given two integers dividend and divisor, divide two integers without using ...

  5. 【LeetCode】分治法 divide and conquer (共17题)

    链接:https://leetcode.com/tag/divide-and-conquer/ [4]Median of Two Sorted Arrays [23]Merge k Sorted Li ...

  6. leetcode-【中等题】Divide Two Integers

    题目 Divide two integers without using multiplication, division and mod operator. If it is overflow, r ...

  7. lintcode 中等题:Divide Two Integers 两个数的除法

    题目 两个整数相除 将两个整数相除,要求不使用乘法.除法和 mod 运算符. 如果溢出,返回 2147483647 . 样例 给定被除数 = 100 ,除数 = 9,返回 11 解题  15%的通过率 ...

  8. [LeetCode] 系统刷题4_Binary Tree & Divide and Conquer

    参考[LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal 可以对binary tree进行遍历. 此处说明Divi ...

  9. 51nod P1305 Pairwise Sum and Divide ——思路题

    久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...

随机推荐

  1. UML由浅入深

    在UML 2.0的13种图形中,类图是使用频率最高的UML图之一.Martin Fowler在其著作<UML Distilled: A Brief Guide to the Standard O ...

  2. MAC地址欺骗(原理及实验)

    MAC地址欺骗 MAC地址欺骗(或MAC地址盗用)通常用于突破基于MAC地址的局域网访问控制,例如在交换机上限定只转发源MAC地址修改为某个存在于访问列表中的MAC地址即可突破该访问限制,而且这种修改 ...

  3. EVE模拟器的配置

    (注:本文整理自达叔的EVE模拟器使用说明https://blog.51cto.com/dashu666/1971728) 基础部署篇 所需要准备的东西: 1.VMWare (虚拟化软件,用来承载模拟 ...

  4. 《JavaScript 模式》读书笔记(6)— 代码复用模式3

    我们之前聊了聊基本的继承的概念,也聊了很多在JavaScript中模拟类的方法.这篇文章,我们主要来学习一下现代继承的一些方法. 九.原型继承 下面我们开始讨论一种称之为原型继承(prototype ...

  5. 基于Atlas实现mysql读写分离

    一.实验环境 主机名IP地址 master192.168.200.111 slave192.168.200.112 atlas192.168.200.113 主从复制不再赘述,链接地址:授权Atlas ...

  6. Python 3之bytes新特性

    转载: Python 3最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分. 文本总是Unicode,由str类型表示,二进制数据则由bytes类型表示. Python 3不会以任意隐式的方 ...

  7. Golang项目部署

    文章来源:https://goframe.org/deploymen... 一.独立部署 使用GF开发的应用程序可以独立地部署到服务器上,设置为后台守护进程运行即可.这种模式常用在简单的API服务项目 ...

  8. Vs Code在Vue项目中v-for指令提示错误的解决办法

    最近在做一个Vue项目,在其中用到v-for指令时,发现Vs Code报错,如下图(代码是没有任何问题的),在网上找了一下解决办法,希望能帮助到更多人. 解决方法: 打开    文件-首选项-设置 将 ...

  9. Eclipse 全部快捷一览表(具TM全)

    1. 编辑快捷键 编辑快捷键 介绍 psvm + Tab 生成main方法 sout + tab 生成输出语句 Ctrl+X / Ctrl + Y 删除一行 Ctrl+D 复制一行 Ctrl+/ 或 ...

  10. 数学--数论--Miller_Rabin判断素数

    ACM常用模板合集 #include<iostream> #include<algorithm> #include<cstring> #include<cst ...