当前位置:网站首页>OJ 1451 digital games
OJ 1451 digital games
2022-07-28 06:38:00 【JETECHO】
describe
Given an integer n.
You can use this number to do any of the following ( It could be zero ) frequency :
If n Can be 2 to be divisible by , Then use n/2 Instead of n;
If n Can be 3 to be divisible by , Then use 2n/3 Instead of n;
If n Can be 5 to be divisible by , Just use 4n/5 Instead of n.
for example , You can use the first operation to 30 Replace with 15, Using the second operation will 30 Replace with 20, Or use the third operation to 30 Replace with 24.
Your task is to find out from n Get in 1 Minimum number of steps required , Or this is impossible .
You must answer independently of q Query for .
Print the answer to each query in a new row . If you can't get from n Get in 1, Then print -1. otherwise , The minimum number of steps required for printing .
Input
The first line of input contains an integer q(1≤q≤1000)—— Number of queries .
Next q The row contains the query . For each query , There is an integer n(1≤n≤1018).
Output
Print the answer of each query in each row . If you can't get from n Get in 1, Then print -1. otherwise , The minimum number of steps required for printing .
Digital games
describe
Given an integer n.
You can use this number to do any of the following ( It could be zero ) frequency :
If n Can be 2 to be divisible by , Then use n/2 Instead of n;
If n Can be 3 to be divisible by , Then use 2n/3 Instead of n;
If n Can be 5 to be divisible by , Just use 4n/5 Instead of n.
for example , You can use the first operation to 30 Replace with 15, Using the second operation will 30 Replace with 20, Or use the third operation to 30 Replace with 24.
Your task is to find out from n Get in 1 Minimum number of steps required , Or this is impossible .
You must answer independently of q Query for .
Print the answer to each query in a new row . If you can't get from n Get in 1, Then print -1. otherwise , The minimum number of steps required for printing .
Input
The first line of input contains an integer q(1≤q≤1000)—— Number of queries .
Next q The row contains the query . For each query , There is an integer n(1≤n≤1018).
Output
Print the answer of each query in each row . If you can't get from n Get in 1, Then print -1. otherwise , The minimum number of steps required for printing .
sample input 1
7
1
10
25
30
14
27
1000000000000000000
sample output 1
0
4
6
6
-1
6
72
The problem requires that the data be changed into 1, If a number changes many times and becomes a non Can be 2,3,5 The number divided by an integer, then this data cannot become 1, Otherwise, the number of steps may be less , Then the reduction should also be as large as possible , Cut from small to large 1/2,2/3,4/5, Then use this rule to analogy .
#include <iostream>
using namespace std;
long long MIN;
void doit (long long a,int cont)
{
if(a%2==0)
{
if(a/2==1)
{
if(MIN>cont)
MIN=cont;
}
else
doit(a/2,cont+1);
}
else if(a%3==0)
{
if(2*a/3==1)
{
if(MIN>cont)
MIN=cont;
}
else
doit(2*a/3,cont+1);
}
else if(a%5==0)
{
if(4*a/5==1)
{
if(MIN>cont)
MIN=cont;
}
else
doit(4*a/5,cont+1);
}
else
MIN=-1;
}
int main()
{
long long n,a;
while(cin>>n)
{
while(n--)
{
MIN=0x3f3f3f;
cin>>a;
if(a==1)
cout<<"0"<<endl;
else
{
doit(a,1);
cout<<MIN<<endl;
}
}
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Icc2 (IV) routing and postroute optimization
Hugging face's problem record I
C语言的动态内存管理函数
OJ 1045 reverse and add
SSAO By Computer Shader(一)
江中ACM新生10月26日习题题解
scrapy 定时执行
Pyppeteer 被识别 绕过检测
C语言的编译和预处理
NFT data storage blind box + mode system development
1、 Ffmpeg record audio as PCM file
开放式耳机推荐哪款最好、性价比最高的开放式耳机
error: redefinition of ‘xxx‘
新的selenium
量化交易机器人系统开发
Several methods of QT setting loading interface
OJ 1505 保险丝
OJ 1018 报数游戏
ubunut 服务器上传下载文件
小程序创建组件









