题目:

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.

Example

Input

7
1
10
25
30
14
27
1000000000000000000

Output

0
4
6
6
-1
6
72

  虽然这是一道基础签到题,但是还真不怎么会,问了别人才知道还能这么玩。

  • 至于权重是这么来的:因为除以3后还要乘以2,所以还要再除一次2才能让n成为1,因为经过两次n才成为1,所以贡献值也就是权重是2;同理,n/5的权重也这么来,因为除以5后又要乘以4,4要被2除两次才为1,一共要除三次,所以权重为3,即算出来的cnt前面的系数是3.。

代码:

 #include<iostream>
using namespace std; int main()
{
int t;
scanf("%d", &t);
while (t--)
{
long long int n;
cin >> n;
int cnt1 = , cnt2 = , cnt3 = ;
while (n % == )
{
n = n / ;
cnt1++;
}
while (n % == )
{
n = n / ;
cnt2++;
}
while (n % == )
{
n = n / ;
cnt3++;
}
if(n != )
cout << "-1" << endl;
else
{
int sum = cnt1 + * cnt2 + * cnt3;  //系数为贡献值类似权重一样的东西
cout << sum << endl;
}
}
return ;
}

A - Divide it! CodeForces - 1176A的更多相关文章

  1. Codeforces 1176A Divide it!

    题目链接:http://codeforces.com/problemset/problem/1176/A 思路:贪心,对第二个操作进行俩次等于将n变成n/3,第三个操作同理,我们将n不断除以2,再除以 ...

  2. CodeForces - 1176A Divide it! (模拟+分类处理)

    You are given an integer nn. You can perform any of the following operations with this number an arb ...

  3. Divide Candies CodeForces - 1056B (数学)

    Arkady and his friends love playing checkers on an n×nn×n field. The rows and the columns of the fie ...

  4. codeforces 792C. Divide by Three

    题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧. ...

  5. Divide by three, multiply by two CodeForces - 977D (思维排序)

    Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, a ...

  6. [codeforces Mail.Ru Cup 2018 Round 3][B Divide Candies ][思维+数学]

    https://codeforces.com/contest/1056/problem/B 题意:输入n,m    求((a*a)+(b*b))%m==0的(a,b)种数(1<=a,b<= ...

  7. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  8. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  9. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

随机推荐

  1. 1.Redis简介/配置文件

    redis简介 redis使用入门 redis安装 http://www.runoob.com/redis/redis-install.html [root@yz---- bin]# ll total ...

  2. Git上传代码命令

    对于Git在这不做说明:只介绍Git使用过程中的常用命令: 一.创建仓库,提交文件 1.初始化一个Git仓库,使用git init命令. 2.添加文件到Git仓库,分两步: 第一步,使用命令git a ...

  3. java 中static关键字注意事项

    1.内存中存放的位置:(static修饰的方法和属性保存在方法区中,但是方法区也是堆的一部分) 内存的分区 2.什么样的属性可以定义为静态数据 例如: class person{ public Str ...

  4. python3 文件流

    文件流 # python里的打开一个文件用open(),如果不能打开,会抛出异常:OSError # 文件流的基本参数 # . file: 打开一个文件 # . mode: 打开的模式,默认模式为tx ...

  5. 框架-Spring容器

    1.   Spring Ioc容器 容器是Spring框架的基础,容器会创建.串联.配置对象,并且能管理对象的整个生命周期.如下是代表 Spring工作原理 MetaData 指定哪些对象实例化.配置 ...

  6. nginx 反向代理学习

    目录 nginx 反向代理学习 一.正向代理和反向代理的区别 1.1正向代理 1.2 反向代理 二.nginx反向代理的使用 nginx 反向代理学习 一.正向代理和反向代理的区别 正向代理代理客户端 ...

  7. 题解-------CF235B Let's Play Osu!

    传送门 题目大意 求出总得分的期望值. 思路 还没有学习数学期望的小朋友赶紧去学一下数学期望,这里只提供公式: $E\left ( x \right )=\sum_{k=1}^{\infty }x_{ ...

  8. 吴裕雄--天生自然python Google深度学习框架:经典卷积神经网络模型

    import tensorflow as tf INPUT_NODE = 784 OUTPUT_NODE = 10 IMAGE_SIZE = 28 NUM_CHANNELS = 1 NUM_LABEL ...

  9. java加载property文件配置

    1 properties简介: properties是一种文本文件,内容格式为:     key = value     #单行注释 适合作为简单配置文件使用,通常作为参数配置.国际化资源文件使用. ...

  10. python3.7解释器安装及配置虚拟环境

    目录 环境准备 一.开始安装解释器(安装很简单,直接上图) 二.配置pip工具下载源 安装虚拟环境 环境准备 1.Windows系统,本人是 Windows10专业版 2.python解释器安装包,本 ...