A - Divide it! CodeForces - 1176A
题目:
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
虽然这是一道基础签到题,但是还真不怎么会,问了别人才知道还能这么玩。
- 至于权重是这么来的:因为除以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的更多相关文章
- Codeforces 1176A Divide it!
题目链接:http://codeforces.com/problemset/problem/1176/A 思路:贪心,对第二个操作进行俩次等于将n变成n/3,第三个操作同理,我们将n不断除以2,再除以 ...
- CodeForces - 1176A Divide it! (模拟+分类处理)
You are given an integer nn. You can perform any of the following operations with this number an arb ...
- 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 ...
- codeforces 792C. Divide by Three
题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧. ...
- 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 ...
- [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<= ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Python笔记_第一篇_面向过程_第一部分_1.Python环境的设置(含虚拟机)
*Python环境的设置 Python的环境设置也就是所需工作平台的软件搭建.常用的搭建平台IOS系统+Linux系统和Windows+Linux系统的搭建.这里主要说明的是Windows+Linux ...
- 用Chrome网页获取PDF?
在网页浏览的时候,我常常想保存网页上的内容 这时候有几种选择,要么copy and paste,要么windows自带截图,要么就是借用tencent的截图工具... 但是对于一些用chrome预览的 ...
- Java之线程通信的方法
/** * 线程通信的例子:使用两个线程打印 1-100.线程1, 线程2 交替打印 * * 涉及到的三个方法: * wait():一旦执行此方法,当前线程就进入阻塞状态,并释放同步监视器. * no ...
- java截取字符串并拼接
一.substirng public static void main(String[] args) { String sendContent = "请查收:www.baidu.com&qu ...
- ae基础二
纯色文本操作快捷键:选中图层点击快捷键(变换)锚点:a(调节中心点)位置:p(左右移动)(利用位置k帧做动画)缩放:s(水平翻转垂直翻转)旋转:r(围绕中心点(锚点)进行旋转)不透明度:tu选中索引 ...
- 套接字详解(socket)
用户认为的信息之间传输只是建立以两个应用程序上,实际上在TCP连接中是靠套接字来作为他们连接的桥梁. 那么什么是套接字呢? TCP用主机的IP地址加上主机上的端口号作为TCP连接的端点,这种端点就叫做 ...
- python代码技术优化
numba 编译优化 from numba import jit @jit def eval_mcc(y_true, y_prob, threshold=False): idx = np.argsor ...
- 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十二天】(系统架构讲解、nginx)
https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...
- C#的静态方法和实例化方法的区别
C#的静态方法和实例化方法的区别 在大多数时候,我们写一个方法,会把方法区分为实例化方法和静态方法.而当被问到静态方法和实例化方法的区别的时候,我在写这篇文章的前10分钟,或许我会回答:"静 ...
- memory barrier 内存栅栏 并发编程
并发编程 memory barrier (内存栅栏) CPU级 1.CPU中有多条流水线,执行代码时,会并行进行执行代码,所以CPU需要把程序指令 分配给每个流水线去分别执行,这个就是乱序执行: 2. ...