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 ...
随机推荐
- Linux 杀掉所有Java进程
ps -ef | grep java | grep -v grep | awk '{print $2}' | xargs kill -9 管道符"|"用来隔开两个命令,管道符左 ...
- C++构造函数概念作用
作用: 对对象进行初始化,如给成员变量赋初值,而不用专门再写初始化函数. 防止有些对象没被初始化就使用,导致程序出错. 要求: 名字与类名相同,可以有参数,但不能有返回值(void也不行) 编译时: ...
- 85.常用的返回QuerySet对象的方法使用详解:defer,only
defer(),only(): 这两个方法都会返回一个"QuerySet"对象,并且这个"QuerySet"中装的是模型,不像values()和values_l ...
- 猜数字游戏(随机数和Scannner的应用)
在指定范围内生成一个随机数作为目标值,用户对目标值进行猜测. import java.util.Random; // 随机数 import java.util.Scanner; // 获取用户输入 p ...
- nouveau :failed to create kernel chanel,-22
一:錯誤描述:今天在重啓 Ubuntu 的過程中,出現下圖的 grub 選項,系統重啓/開機之後出現以下畫面,然後選擇 Ubuntu 之後黑屏,提示錯誤:nouveau :failed to crea ...
- .jar文件不能解析、识别
- React 渲染嵌套对象,内部对象会是undefined
在编译器中获取数据 发现报错 原因: render()一加载就会渲染,渲染的数据是初始state里的值 ,当setState会再次渲染 解决方法 1.三元运算 判断对象是否存在 2.在初始化对象的时候 ...
- maven坐标 加速下载
<repositories> <repository> <id>aliyun</id> <name>aliyun</name> ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:数据集高层操作
import tempfile import tensorflow as tf # 1. 列举输入文件. # 输入数据生成的训练和测试数据. train_files = tf.train.match_ ...
- Spring IOC 和AOP
Spring是什么? Spring是一个轻量级的IoC和AOP容器框架. IOC:IOC就是控制反转,控制反转指的是把创建对象和管理对象之间的依赖关系交给了IOC容器来管理.以前new对象由程序员来控 ...