CodeForces - 1176A Divide it! (模拟+分类处理)
You are given an integer nn.
You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:
Replace nn with n2n2 if nn is divisible by 22;
Replace nn with 2n32n3 if nn is divisible by 33;
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
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
long long n;
scanf("%lld", &n);
int l = 0, m = 0, p = 0;
for (; n % 2 == 0; n /= 2, l++)
;
for (; n % 3 == 0; n /= 3, m++)
;
for (; n % 5 == 0; n /= 5, p++)
;
printf("%d\n", n == 1 ? (l + 2 * m + 3 * p) : -1);
}
return 0;
}
CodeForces - 1176A Divide it! (模拟+分类处理)的更多相关文章
- Codeforces 1176A Divide it!
题目链接:http://codeforces.com/problemset/problem/1176/A 思路:贪心,对第二个操作进行俩次等于将n变成n/3,第三个操作同理,我们将n不断除以2,再除以 ...
- CodeForces 792C - Divide by Three [ 分类讨论 ]
删除最少的数位和前缀0,使得剩下的数能被3整除 等价于各数位数字之和能被3整除. 当前数位和可能是 0, 1, 2(mod 3) 0: 直接处理 1: 删除一个a[i]%3 == 1 或者 两个a[i ...
- codeforces 792C. Divide by Three
题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧. ...
- A - Divide it! CodeForces - 1176A
题目: You are given an integer nn. You can perform any of the following operations with this number an ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 658A. Robbers' watch 模拟
A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
随机推荐
- 汇编刷题:根据公式 Z=(X+Y)*8-X)/4 计算Z的结果(本题将结果放在AL寄存器里)
DATA SEGMENT X DB 10 Y DB 20 Z DB 00 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DAT ...
- String 对象-->toUpperCase() 方法
1.定义和用法 将字符串中所有的小写字符转换成大写字符,大写字符保持不变 返回转换后的结果字符串 语法: string.toUpperCase() 注意:不会改变字符串本身,仅以返回值的形式返回结果 ...
- matplotlib locators
2020-03-23 17:59:59 -- Edit by yangray The Locator class is the base class for all tick locators. Th ...
- CVE-2020-1938:Apache-Tomcat-Ajp漏洞-复现
0x00 漏洞简介 Apache与Tomcat都是Apache开源组织开发的用于处理HTTP服务的项目,两者都是免费的,都可以做为独立的Web服务器运行. Apache Tomcat服务器存在文件包含 ...
- IKAnalyzer修改支持lucene8.0
源码已经上传GitHub. 如果直接使用jar:IKAnalyzer-5.0.2. 在这我只是在原有代码结构上做了微调,让代码支持lucene8.0.
- spring中BeanPostProcessor之三:InitDestroyAnnotationBeanPostProcessor(01)
在<spring中BeanPostProcessor之二:CommonAnnotationBeanPostProcessor(01)>一文中,分析到在调用CommonAnnotationB ...
- Python - 实现文件名自动更改,避免同名文件被覆盖的两个解决方法
[原创]转载请注明作者Johnthegreat和本文链接. 在一些不多的数据下载和生成的时候,我们倾向于直接保存为文件,当我们修改某些参数后再一次运行时,之前运行时生成的文件就被覆盖了.为了解决这个问 ...
- 测试需要用到的chrome调试
模拟慢网速 断开网络 F12后勾选上offline 请求304 后来发现是选中了该浏览其的Disable cache,去掉就好了.
- keras API的使用,神经网络层,优化器,损失函数,查看模型层数,compile和fit训练
layers介绍 Flatten和Dense介绍 优化器 损失函数 compile用法 第二个是onehot编码 模型训练 model.fit 两种创建模型的方法 from tensorflow.p ...
- tensorflow版线性回归
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf def linearregression(): X ...