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 ...
随机推荐
- SQLI-LABS学习笔记(一)
逼话少说,如有错误,烦请指出,谢谢. 第一关 提示传个id的参数 后面跟个单引号 http://10.2.10.31/sqli/Less-1/?id=1’ 发现报错,这里看到是已经闭合了 You ha ...
- 怎么在java中创建一个自定义的collector
目录 简介 Collector介绍 自定义Collector 总结 怎么在java中创建一个自定义的collector 简介 在之前的java collectors文章里面,我们讲到了stream的c ...
- 数据挖掘入门系列教程(十二)之使用keras构建CNN网络识别CIFAR10
简介 在上一篇博客:数据挖掘入门系列教程(十一点五)之CNN网络介绍中,介绍了CNN的工作原理和工作流程,在这一篇博客,将具体的使用代码来说明如何使用keras构建一个CNN网络来对CIFAR-10数 ...
- 单源最短路问题--朴素Dijkstra & 堆优化Dijkstra
许久没有写博客,更新一下~ Dijkstra两种典型写法 1. 朴素Dijkstra 时间复杂度O(N^2) 适用:稠密图(点较少,分布密集) #include <cstdi ...
- 我的Android进阶之旅------> Android为TextView组件中显示的文本加入背景色
通过上一篇文章 我的Android进阶之旅------> Android在TextView中显示图片方法 (地址:http://blog.csdn.net/ouyang_peng/article ...
- 通过fiddler抓取IDEA的请求
2019独角兽企业重金招聘Python工程师标准>>> 因为fiddler默认是代理的8888端口,所以设置一下IDEA的请求使用本地的8888作为代理发出. 1."EDI ...
- Java_Web--JDBC 增加记录操作模板
如果不能成功链接数据库,我的博客JAVA中有详细的介绍,可以看一下 import java.sql.Connection; import java.sql.DriverManager; import ...
- 转载acm几何基础(2)
判断两条线段是否相交: 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果有向线段p1p2的起点p1在坐标的原点,则可以把它称为矢量p2 矢量的加减 设二维矢量 P = (x ...
- redis系列之5----redis实战(redis与spring整合,分布式锁实现)
本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...
- Python爬虫(二)爬百度贴吧楼主发言
爬取电影吧一个帖子里的所有楼主发言: # python2 # -*- coding: utf-8 -*- import urllib2 import string import re class Ba ...