CF1176A.Divide it!

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 n2\frac{n}{2} if nn is divisible by 22;
  2. Replace nn with 2n3\frac{2n}{3} if nn is divisible by 33;
  3. Replace nn with 4n5\frac{4n}{5} 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.

给你一个整数 nn。

你可以对这个数执行以下任意一种操作,次数不限(可以为零次):

  1. 若 nn 能被 22 整除,则将 nn 替换为 n2\frac{n}{2};
  2. 若 nn 能被 33 整除,则将 nn 替换为 2n3\frac{2n}{3};
  3. 若 nn 能被 55 整除,则将 nn 替换为 4n5\frac{4n}{5}。

例如,你可以对 3030 执行第一种操作得到 1515,执行第二种操作得到 2020,或执行第三种操作得到 2424。

你的任务是:求出将 nn 变为 11 所需的最少操作步数;若无法变为 11,则说明这是不可能的。

你需要回答 qq 个相互独立的查询。

输入格式

The first line of the input contains one integer qq (1≤q≤10001 \le q \le 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 \le n \le 10^{18}).

输入的第一行包含一个整数 qq(1≤q≤10001 \le q \le 1000)—— 表示查询的次数。

接下来的 qq 行包含各次查询。对于每次查询,你将得到一个整数 nn(1≤n≤10181 \le n \le 10^{18})。

输出格式

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.

每个查询的答案单独输出一行。如果无法从 nn 得到 11,则输出 -1;否则,输出实现该目标所需的最少操作步数。

输入输出样例

  • 输入#1

    7
    1
    10
    25
    30
    14
    27
    1000000000000000000

    输出#1

    0
    4
    6
    6
    -1
    6
    72

输入解题思路,AI测评打分。不知道怎么写?

首页