我是靠谱客的博主 兴奋摩托,最近开发中收集的这篇文章主要介绍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("%dn", n == 1 ? (l + 2 * m + 3 * p) : -1);
	}
	return 0;
}

 

最后

以上就是兴奋摩托为你收集整理的A. Divide it!的全部内容,希望文章能够帮你解决A. Divide it!所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部