题目如下:
JATC’s math teacher always gives the class some interesting math problems so that they don’t get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times:

mul x: multiplies n by x (where x is an arbitrary positive integer).
sqrt: replaces n with n−−√ (to apply this operation, n−−√ must be an integer).
You can perform these operations as many times as you like. What is the minimum value of n, that can be achieved and what is the minimum number of operations, to achieve that minimum value?

Apparently, no one in the class knows the answer to this problem, maybe you can help them?

Input
The only line of the input contains a single integer n (1≤n≤106) — the initial number.

Output
Print two integers: the minimum integer n that can be achieved using the described operations and the minimum number of operations required.

Examples
Input
20
Output
10 2
Input
5184
Output
6 4
Note
In the first example, you can apply the operation mul 5 to get 100 and then sqrt to get 10.

In the second example, you can first apply sqrt to get 72, then mul 18 to get 1296 and finally two more sqrt and you get 6.

Note, that even if the initial value of n is less or equal 106, it can still become greater than 106 after applying one or more operations.

题意:
大概是输入一个数,用平方根和乘法对其进行运算,使其达到最小值并输出结果和最小步骤数。

思路:
一开始看到这个题的时候想用暴力,但是一想不太行,后来翻看到老的文章,看到了因数二字,心中有了想法。。。
一个数由好多最小因数组成,经过这一系列运算,那个最小的数就是所有可能因子的乘积
那一系列运算究竟是什么样的运算呢?怎么安排乘法和开方?
后来一想,哦,想要达到最小值得让那些因数的个数变为偶数才可以进行开方,乘法无异于是引入因数,让其个数变为偶数, 乘法只需要进行一次即可
为了让每个因数的个数都变为1,前提是需保证个数最多的那个因数的个数变为1,并且需要将其个数变为2的幂次方(>=原个数)再求log2就是总体需要开方的次数,如果前面的乘法运算存在的话开方次数+1就是总共要运算的次数

我的AC代码:

#include <iostream>
#include <cmath>
#define LL long long int
using namespace std;struct note{int a;int n;
};
struct note yin[20];int f(int p){int top = (int)sqrt((double)p);int i;for(i = 2; i <= top; i++){if(p % i == 0) return i;}return p;//最小因子就是他自己。。。。
}int main(void){LL in; cin>>in;int head = 0,tail = 0;int i;int flag;while(in != 1){//获得所有因子信息 int tyin = f(in);flag = 0;for(i = head; i < tail; i++){if(yin[i].a == tyin){yin[i].n++;flag = 1;}}if(flag != 1){yin[tail].a = tyin;yin[tail].n  = 1;tail++;}in /= tyin;}int k = 1;for(i = head; i < tail; i++) k *= yin[i].a; int maxer = -1;for(i = head; i < tail; i++) maxer = max(maxer, yin[i].n);int ce = 1;while(ce < maxer) ce *= 2;int step = 0;       for(i = head; i < tail; i++) if(ce != yin[i].n){step++;break;}while(ce != 1){ce /= 2;step++;}cout<<k<<" "<<step<<endl;return 0;
}

修改和加注释以后的代码:

#include <iostream>
#include <cmath>
#define LL long long int
using namespace std;struct note{int a;int n;
};int f(int p){//求最小因子的函数 int top = (int)sqrt((double)p);int i;for(i = 2; i <= top; i++){ //如果输入2,3 这里并不执行 if(p % i == 0) return i;}return p;//最小因子就是他自己。。。。
}int main(void){int in; cin>>in;struct note yin[20];int head = 0,tail = 0;//用个队列存储 int i;int flag;while(in != 1){//获得所有因数及其个数 int t = f(in);for(i = head; i < tail; i++){//扫描是否已经被记录 if(yin[i].a == t){//有的话个数+1 yin[i].n++;break;}}if(i == tail){//没有记录 //这里对flag进行了优化 yin[tail].a = t;yin[tail].n  = 1;tail++;//入队操作 }in /= t;//除以那个因数 }int miner = 1;int maxer = -1;   for(i = head; i < tail; i++){maxer = max(maxer, yin[i].n);//找到个数最多的那个因数 miner *= yin[i].a; //求出那个最小值 } int step = 0;int base = 1;while(base < maxer){//求出最小二次幂值 base *= 2;step++;}for(i = head; i < tail; i++) //判断是否进行了乘法操作  if(base > yin[i].n){step++;break;}cout<<miner<<" "<<step<<endl;return 0;
}

*开方就是指数除以2

*乘法就是引入因数

题目让求最小值,那就要去考虑给定的操作可以让数的属性发生哪些变化

再看一下dalao的思路

#include<iostream>
using namespace std;
int main(void)
{long long int n; cin >> n;if (n == 1) cout << "1 0" << endl;else {long long int ans = 1, num = 0, m = n;int i;for (i = 2; ; i++) {if (m == 1) break;if (m % i == 0) ans *= i;//如果是因数,载入while (m % i == 0) m /= i;//然后把这个因数消除掉}long long int x = ans;while (x % n) {//被除尽还有这样一层含义。。。x *= x;//这里也很妙,用乘法代替开开方num++;}if (x > n) num++;//这个是否进行过乘法运算的判断也很妙cout << ans << " " << num << endl;}return 0;
}

hhhh这简洁性这效率 又被大佬摁在地上摩擦 orz

花时间整理,之后一定常来看哦~ (/ω\)

2020-2-16 B - Math相关推荐

  1. 微型计算机2020年6月上,2020年1-6月全国微型计算机设备产量统计分析

    [中国报告大厅讯]根据中国报告大厅对2020年1-6月全国微型计算机设备产量进行监测统计显示:2020年6月全国微型计算机设备产量3216.5万台,同比增长0.3%,2020年1-6月全国微型计算机设 ...

  2. [Android] 迅游加速器 5.1.26.1免费版 2020.6.16更新

    [Android] 迅游加速器 5.1.26.1免费版 2020.6.16更新 蓝奏云下载链接 求关注持续跟新

  3. Visual.Assist.X.10.9.Build.2375.0 2020.05.16 最新版

    Visual.Assist.X.10.9.Build.2375.0 2020.05.16 最新版,带特殊文件,解压后查看使用说明. VC++编程助手,支持VS 2019,亲测可用. 共享备用. 7zi ...

  4. 谈谈mini2440开发板的学习路线以及分享开发板的最新资料[minitools v1.9a...](更新时间:2020/05/16))

    谈谈mini2440开发板的入门学习路线以及分享开发板的最新资料[minitools v1.9a...](更新时间:2020/05/16) 简介 因为毕设,自己也在学习mini2440开发板,但是它实 ...

  5. 纪中集训2020.01.16【NOIP普及组】模拟赛C组总结+【0.Matrix】分析

    纪中集训2020.01.16[NOIP普及组]模拟赛C组总结+[0.Matrix]分析 题目: 0.matrix 1.product 2.binary 3.value 巨佬估分:100+100+40+ ...

  6. 数据分享和开源软件有助于对抗新型冠状肺炎,开源布道师等;开源之道每周评论2020 03 16...

    ▼ 更多精彩推荐,请关注我们 ▼ 声明:本文所言论,仅代表适兕个人观点 共同体工作项列表 原文链接:Community Worksheet Downloads 适兕点评: 我很想知道,为何费孝通先生当 ...

  7. FPGA开发工具套餐搭配推荐及软件链接 (更新于2020.03.16)

    一.Xilinx(全球FPGA市场份额最大的公司,其发展动态往往也代表着整个FPGA行业的动态) (1) Xilinx官方软件下载地址链接: https://china.xilinx.com/supp ...

  8. 【2020/07/16修订】概率论与数理统计(电子科技大学) 知识梳理 · 第一版(1到8章 · 度盘)

    概率论与数理统计 知 识 梳 理 (第一版) 建议先修课程:高等数学(微积分) 配套课程: 1.慕课(MOOC):概率论与数理统计(电子科技大学) 2.教材:概率论与数理统计 电子科技大学应用数学学院 ...

  9. 2020.7.16 bug总结 第二周 (转载篇)

    目录 1.HTML图片标签空白解决方法 2.[js 动态添加更改]: 注意转义\ 和' '的使用 3.git中fatal: Authentication failed的问题]输错了密码 ,手快按了确定 ...

  10. 2020年1-6月份Java面试题总结,20多类1100道面试题含答案解析

    很多程序员都会担心35岁的职业危机,而数据也显示,40岁以上的程序员几乎不存在,大都转了管理岗,余下的只能被迫离职或者转行.然而,太久待在舒适区,可能连小公司的面试,都很难通过了. 程序员是最需要将终 ...

最新文章

  1. 05.序列模型 W1.循环序列模型
  2. OJ1017: 表面积和体积
  3. 事物与持久化_DDD之聚合持久化应该怎么做?
  4. Qt中焦点策略FocusPolicy的使用
  5. Sql 行转换列(列转换行), JavaScript解决思路
  6. 【故障分析】基于matlab ICA故障监测【含Matlab源码 1591期】
  7. 齿轮标准模数c语言编程,标准齿轮模数齿数计算公式汇总.pdf
  8. 个人收集资料分享(电子、计算机相关)
  9. 计算机 服装生产管理的变化,服装生产与管理服装生产管理概述.ppt
  10. python英文文本词性分析
  11. windows系统排查-文件分析
  12. Leetcode 318. Maximum Product of Word Lengths
  13. php获取企业微信聊天内容,微信企业号开发获取用户信息的介绍
  14. 大学生上课为什么一定要认真听讲?
  15. ijkplayer编译生成aar,支持https,rtsp,录制与截图
  16. iOS支付宝、微信支付
  17. request.getContextPath详解
  18. 电影影评的文本分类——基于tensorflow
  19. Android_多渠道打包_混淆
  20. 网络协议 -- ICMP协议(1) 报文格式

热门文章

  1. 360校园招聘2015届技术类笔试题(一)
  2. 在c语言如何对拨码开关编程,拨码开关控制实验
  3. 使用Visual Studio Code 进行Python编程(二)-print、if、for的用法
  4. 怎么把不能编辑的qlv转换成mp4
  5. 安全防御(三)--- IDS、防火墙入侵防御
  6. 【HEVC简介】CTU、CU、PU、TU结构
  7. [学习笔记] 《精准营销:社会化媒体时代企业传播实战指南》
  8. 重学计算机组成原理(十一)- 门电路的千里传音
  9. 微信自动检测色情图片_python +itchat
  10. matlab经纬度画轨迹图_MATLAB将经纬度坐标转换成直角坐标