Codeforces1176A(A题)Divide it!
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.
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).
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.
代码:
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int q;
long long a[];
cin>>q;
for(int i=; i<q; i++) {
cin>>a[i];
}
for(int q1=;q1<q;q1++){
int cnt=;
while(a[q1]!=) {
if(a[q1]%!=&&a[q1]%!=&&a[q1]%!=){
cnt=-;
break;
}
if(a[q1]%==) {
a[q1]/=;
cnt++;
}
if(a[q1]%==) {
a[q1]=a[q1]*/;
cnt++;
}
if(a[q1]%==) {
a[q1]=a[q1]*/;
cnt++;
}
if(a[q1]==){
break;
}
}
cout<<cnt<<endl;
}
}
思路分析:数要是不能被3,5,2整除,就设置cnt为-1并输出。先除2/n再2n/3z再4n/5统计次数,最后化为1,输出cnt。
Codeforces1176A(A题)Divide it!的更多相关文章
- leetcode第28题--Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 分析:题目意思很容易理解,就是不用乘除法和模运 ...
- java中的位操作
之前做项目的时候使用位操作不是很多,今天在刷leetcode上题目的时候用到了位操作,是leetcode中的第29题Divide Two Integers. 一.java的位操作: 位运算表达式由操作 ...
- 【LeetCode每天一题】Divide Two Integers(两整数相除)
Given two integers dividend and divisor, divide two integers without using multiplication, division ...
- LeetCode第[29]题(Java):Divide Two Integers
题目:两整数相除 难度:Medium 题目内容: Given two integers dividend and divisor, divide two integers without using ...
- 【LeetCode】分治法 divide and conquer (共17题)
链接:https://leetcode.com/tag/divide-and-conquer/ [4]Median of Two Sorted Arrays [23]Merge k Sorted Li ...
- leetcode-【中等题】Divide Two Integers
题目 Divide two integers without using multiplication, division and mod operator. If it is overflow, r ...
- lintcode 中等题:Divide Two Integers 两个数的除法
题目 两个整数相除 将两个整数相除,要求不使用乘法.除法和 mod 运算符. 如果溢出,返回 2147483647 . 样例 给定被除数 = 100 ,除数 = 9,返回 11 解题 15%的通过率 ...
- [LeetCode] 系统刷题4_Binary Tree & Divide and Conquer
参考[LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal 可以对binary tree进行遍历. 此处说明Divi ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
随机推荐
- tp5--开发规范
在日常开发的过程中,写代码都要有一定的规范,不然可读取就太差了,所以为了以后的维护.对接,好的代码规定是必须的. 以下是我自己对自己提出的要求: 全部: 1) 每个方法都要写好备注(@retrun作 ...
- 超详细步骤---Linux下的最新Git版本安装
原文地址:https://blog.csdn.net/u010887744/article/details/53957613 [标注大头] 1.查看当前git版本:git --version 查看最新 ...
- python学习23之标准库
'''''''''标准库1.datetime 日期时间模块存在于Lib/datetime.py文件内'''from datetime import datetime,date,time #from d ...
- 文件包含漏洞(pikachu)
文件包含漏洞 在web后台开发中,程序员往往为了提高效率以及让代码看起来更加简洁,会使用'包含'函数功能,比如把一系列功能函数都写进function.php中,之后当某个文件需要调用的时候,就直接在文 ...
- 初篇:我与Linux
据悉,红帽认证将于本年的8月份更换Rhel7为Rhel8.所以我想趁这次机会搏一搏. 我个人是初中就神仰Linux已久,只不过那个时候的我只知道Linux系统,不知道有什么区分.奈何那 ...
- 【linux题目】第一关
详细的解答:https://github.com/Zoe233/Linux/blob/master/[题目]5.Linux了解程度测试题解析.ipynb 1. 创建一个目录/data 解答: mkdi ...
- CentOS 7 编译错误解决方法集合
解决 error: the HTTP XSLT module requires the libxml2/libxslt 错误 yum -y install libxml2 libxml2-dev yu ...
- HTML(表单标签)
<form> 标签 用于为用户输入创建 HTML 表单 表单能够包含 input 元素,比如:文本字段.复选框.单选框.提交按钮等等 表单用于向服务器传输数据 action 属性:规定当提 ...
- 3) drf 框架生命周期 请求模块 渲染模块 解析模块 自定义异常模块 响应模块(以及二次封装)
一.DRF框架 1.安装 pip3 install djangorestframework 2.drf框架规矩的封装风格 按功能封装,drf下按不同功能不同文件,使用不同功能导入不同文件 from r ...
- 7) 项目准备流程 和 django权限六表
一.项目准备 1. 创建django项目 2. 创建数据库 —— init文件中声明mysql —— settings中配置数据库 import pymysql pymysql.install_as_ ...