You are given an integer nn.

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

Replace nn with n2n2 if nn is divisible by 22;

Replace nn with 2n32n3 if nn is divisible by 33;

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

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
} #define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------// int main()
{
int t;
scanf("%d", &t);
while (t--)
{
long long n;
scanf("%lld", &n);
int l = 0, m = 0, p = 0;
for (; n % 2 == 0; n /= 2, l++)
;
for (; n % 3 == 0; n /= 3, m++)
;
for (; n % 5 == 0; n /= 5, p++)
;
printf("%d\n", n == 1 ? (l + 2 * m + 3 * p) : -1);
}
return 0;
}

CodeForces - 1176A Divide it! (模拟+分类处理)的更多相关文章

  1. Codeforces 1176A Divide it!

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

  2. CodeForces 792C - Divide by Three [ 分类讨论 ]

    删除最少的数位和前缀0,使得剩下的数能被3整除 等价于各数位数字之和能被3整除. 当前数位和可能是 0, 1, 2(mod 3) 0: 直接处理 1: 删除一个a[i]%3 == 1 或者 两个a[i ...

  3. codeforces 792C. Divide by Three

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

  4. A - Divide it! CodeForces - 1176A

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

  5. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  6. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  7. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  8. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  9. Codeforces 658A. Robbers' watch 模拟

    A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

随机推荐

  1. JavaScript form表单提交与验证

    原网址:https://blog.csdn.net/vipwxs/article/details/79119701 一.form对象的属性: name:获取表单的名称,该name一般给JS使用 met ...

  2. (js描述的)数据结构[集合结构](6)

    (js描述的)数据结构[集合结构](6) 一.集合结构特点 1.集合中的元素不能重复. 2.集合是无序的. 二.集合的代码实现 function Set() { this.items = {} //1 ...

  3. Java第二十六天,多线程等待换新机制(严格执行化)

    代码: 1.老板类: package com.lanyue.day26; public class bossRunnable implements Runnable { public myLock l ...

  4. 汇编刷题:求1000H单元开始的10个无符号字节数的最大值(本题放入了BL寄存器)

    DATA SEGMENT ORG 1000H INFO DB 1,2,3,4,5,70H,71H,72H,80H,92H MAX DB 00H DATA ENDS CODE SEGMENT ASSUM ...

  5. 抓包——HTTP分析

      1.什么是HTTP请求(底层使用scoket TCP技术) HTTP是超文本传输协议.底层使用的scoket tcp长连接.基于请求和响应  同步请求. 2.重定向底层: 重定向原理:为什么会产生 ...

  6. lr 遇到的问题

    1.Abnormal termination, caused by mdrv process termination 解决方法:修改LR中的D:\Program Files\Mercury\LoadR ...

  7. Java虚拟机类装载的原理及实现(转)

    Java虚拟机类装载的原理及实现(转) 一.引言 Java虚拟机(JVM)的类装载就是指将包含在类文件中的字节码装载到JVM中, 并使其成为JVM一部分的过程.JVM的类动态装载技术能够在运行时刻动态 ...

  8. Volatile可见性分析(一)

    JUC(java.util.concurrent) 进程和线程 进程:后台运行的程序(我们打开的一个软件,就是进程) 线程:轻量级的进程,并且一个进程包含多个线程(同在一个软件内,同时运行窗口,就是线 ...

  9. x聊之后,又一波新的诈骗套路

    前些天刚看到,x聊勒索诈骗套路,骗子的套路可以说是花样百出,这不又一网友深受其害. 事情经过是这样的 某被骗网友由于工资微薄一直想找副业增加收入,关注和加了很多群. 注意群里都是有偏亮头像的”小姐姐” ...

  10. [算法]Huffman树(哈夫曼树)

    目录 一.关于Huffman树 二.具体实现 例1:P1090 合并果子 例2:P2168 [NOI2015]荷马史诗 一.关于Huffman树 Huffman树(哈夫曼树)可以解决下述问题: 一颗\ ...