题目:

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. 如何快速完成一份学术型PPT

    大多人都知道有模板这么个东西. 但是拿到手却不会运用,所以只得急的找人帮忙. 毕竟一套模板的素材图表和你要展示的内容,很多都太不一样. 这种情况,怎么办?下面就来告诉你.   选中一套模版后,放大看看 ...

  2. java -jar 和 java -cp 的区别

    https://blog.csdn.net/weixin_38653290/article/details/84647019 1.pom中build指定mainClass 但是 META-INF\MA ...

  3. 使用flask_sqlalchemy操作mysql的一个测试

    示例代码 from flask_sqlalchemy import SQLAlchemy from flask import Flask app=Flask(__name__) app.config[ ...

  4. Jupyter notebook 和 Jupyter lab 的区别

    Jupyter Notebook Jupyter Notebook 是一个款以网页为基础的交互计算环境,可以创建Jupyter的文档,支持多种语言,包括Python, Julia, R等等.广泛用于数 ...

  5. LaTeX Windows配置

    1. 安装TeXstudio 用搜索引擎找合适的版本或者 在 https://sourceforge.net/projects/texstudio/ 下载 找合适的版本下载,点击下一步安装即可. Te ...

  6. dht算法原理描述

    dht原理 dht是P2P网络(结构化P2P)核心路由算法,主要是利用一致性hash,把节点和资源都表示成一个hash值,放入到这个大的hash环中,每个节点负责路由靠近它的资源. 一.重要概念:  ...

  7. 洛谷 P3371 【模板】单源最短路径(弱化版)(dijkstra邻接链表)

    题目传送门 解题思路: 传送门 AC代码: #include<iostream> #include<cstdio> #include<cstring> using ...

  8. npm安装依赖报 npm ERR! code Z_BUF_ERROR npm ERR! errno -5 npm ERR! zlib: unexpected end of file 这个错误解决方案

    今天碰到了一个比较奇怪的问题,下载依赖有问题报错 npm ERR! code Z_BUF_ERROR npm ERR! errno -5 npm ERR! zlib: unexpected end o ...

  9. 5 分钟全面掌握 Python 装饰器

    ♚ 作者:吉星高照, 网易游戏资深开发工程师,主要工作方向为网易游戏 CDN 自动化平台的设计和开发,脑洞比较奇特,喜欢在各种非主流的领域研究制作各种不走寻常路的东西. ! Python的装饰器是面试 ...

  10. redhat6.5 升级内核

    1.导入key rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org 2.安装elrepo的yum源 rpm -Uvh https:// ...