题目:

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. php开启opcache

    OPcache 通过将 PHP 脚本预编译的字节码存储到共享内存中来提升 PHP 的性能, 存储预编译字节码的好处就是 省去了每次加载和解析 PHP 脚本的开销. 一.php.ini配置opchche ...

  2. @Component, @Repository, @Service,@Controller的区别

    @Component, @Service, @Controller, @Repository是spring注解,注解后可以被spring框架所扫描并注入到spring容器来进行管理 @Componen ...

  3. tensroflow中如何计算特征图的输出及padding大小

    根据tensorflow中的conv2d函数,我们先定义几个基本符号 1.输入矩阵 W×W,这里只考虑输入宽高相等的情况,如果不相等,推导方法一样,不多解释. 2.filter矩阵 F×F,卷积核 3 ...

  4. Dynamics CRM - 通过 C# Plugin 来 abandon Business Process Flow

    需求说明: 当一个 Entity 存在 Business Process Process 时,有时我们需要改变其状态,在之前写的博客有讲了可以通过 JavaScript 来实现,本篇就来讲一下如何通过 ...

  5. semantic框架 - selection dropdown自定义样式

    semantic和Bootstrap是我最常用的前端框架. 这次需求,是要修改selection dropdown. 直接贴代码,不解释. .ui.form input:not([type]):foc ...

  6. spring前两天

    1,Spring是什么 (1) Spring是JavaEE 一站式,轻量级 容器框架 ① JavaEE :企业级 ② 一站式: JavaWeb开发的三层 直接使用Spring一个框架全部完成 ③ 轻量 ...

  7. 9.windows-oracle实战第九课--plsql

    一.oracle的pl/sql的概念 pl/sql是oracle在标准的sql语言上的扩展,不仅允许嵌入sql,还允许定义变量和常量,允许使用条件语句和循环语句,允许使用例外处理各种错误,这样使得它的 ...

  8. ElasticSearch 分组查询

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' { "size": 0, "aggs": { &qu ...

  9. jQuery篇

    jQuery 1.为什么使用jQuery? js中window onload事件只能出现一次,如果出现多次,后面的事件会覆盖掉前面的事件 js代码容错差 简单的动画效果实现很繁琐,例如简单的动画渐变效 ...

  10. Windows Server 2008 R2 安全加固

    0x00 简介 安全加固是企业安全中及其重要的一环,其主要内容包括账号安全.认证授权.协议安全.审计安全四项,这篇博客简单整理一下Windows Server 2008 R2的安全加固方案. 0x01 ...