A. Divide it!

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy

7
1
10
25
30
14
27
1000000000000000000

output

Copy

0
4
6
6
-1
6
72

 

解题说明:水题,按照题目意思求解即可。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		long long n;
		scanf("%lld", &n);
		int l = 0, m = 0, p = 0;
		while (n % 2 == 0)
		{
			n = n / 2;
			l++;
		}
		while (n % 3 == 0)
		{
			n = n / 3;
			m++;
		}
		while (n % 5 == 0)
		{
			n = n / 5;
			p++;
		}
		printf("%d\n", n == 1 ? (l + 2 * m + 3 * p) : -1);
	}
	return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值