当前位置:网站首页>Acwing weekly contest 57- digital operation - (thinking + decomposition of prime factor)
Acwing weekly contest 57- digital operation - (thinking + decomposition of prime factor)
2022-06-27 22:02:00 【Lovely and beautiful girl】
The question :
Just give you a number n, You can let n Multiply by any positive integer x, Or let n Square root . What is the minimum number you can reach , How many operations does it take to reach this number .
reflection :
At first, I thought it was just a direct violent run , One number n multiply x, Then you can prescribe the formula . Of course it's wrong , It may not be enough . It's actually right n First, we decompose the prime factor , First of all, make sure that the number reached is the minimum , So let's look at the power of each prime factor , Let all powers become the largest power , Then one step at a time , If the current power is not 2 Multiple , That is, you can't directly prescribe the square , Then multiply by this number , Make him 2 Multiple , So use a st Mark , Whether to multiply by the number , No matter how many times , We can all multiply it all for the first time .
Code :
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define db double
#define int long long
#define PII pair<int,int >
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int mod = 1e9+7,inf = 1e18;
const int N = 1e5+10,M = 2010;
int T,n,m,k;
int va[N];
map<int,int > mp;
signed main()
{
IOS;
cin>>n;
if(n==1)
{
cout<<1<<" "<<0;
return 0;
}
for(int i=2;i<=n/i;i++)
{
while(n%i==0)
{
mp[i]++;
n /= i;
}
}
if(n>1) mp[n]++;
int maxn = 0,minn = inf,now = 1;
for(auto t:mp)
{
now = now*t.fi;
maxn = max(maxn,t.se);
minn = min(minn,t.se);
}
int sum = 0,st = 0;
if(minn<maxn) st = 1; // If the power of some prime factors is not enough , Then it's a multiplier
while(maxn>1)
{
if(maxn&1) // If the power is not 2 Multiple , Then multiply by now, Make into 2 Multiple
{
st = 1;
maxn++;
}
maxn /= 2;
sum++;
}
cout<<now<<" "<<sum+st; // The answer is the product of prime factors , The number of times is the number of square root and whether to multiply
return 0;
}
summary :
Think more , Think of some algorithms , It is certainly not right to use uncertain methods .
边栏推荐
- 石子合并问题分析
- GBase 8a OLAP分析函数 cume_dist的使用样例
- 豆沙绿保护你的双眼
- TreeSet details
- Test automatique de Test logiciel - test d'interface de l'introduction à la maîtrise, apprendre un peu chaque jour
- Hash table - sum of arrays
- BAT测试专家对web测试和APP测试的总结
- matlab查找某一行或者某一列在矩阵中的位置
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- Go from introduction to practice -- shared memory concurrency mechanism (notes)
猜你喜欢

Go from starting to Real - Interface (note)

Summary of Web testing and app testing by bat testing experts

Remote invocation of microservices

使用Jmeter进行性能测试的这套步骤,涨薪2次,升职一次

Set code exercise

Système de gestion - itclub (II)

熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊

Management system itclub (Part 2)

单元测试界的高富帅,Pytest框架,手把手教学,以后测试报告就这么做~

AQS SOS AQS with me
随机推荐
Have time to look at ognl expressions
JVM memory structure when creating objects
[LeetCode]186. 翻转字符串里的单词 II
. Net learning notes (V) -- lambda, LINQ, anonymous class (VaR), extension method
Installing Oracle11g under Linux
[LeetCode]186. Flip word II in string
C语言程序设计详细版 (学习笔记1) 看完不懂,我也没办法。
YOLOv6:又快又准的目标检测框架开源啦
[LeetCode]513. 找树左下角的值
C language programming detailed version (learning note 1) I can't understand it after reading, and I can't help it.
linux下安装oracle11g 静默安装教程
[leetcode] dynamic programming solution split integer i[silver fox]
It smells good. Since I used Charles, Fiddler has been completely uninstalled by me
QT base64 encryption and decryption
∫(0→1) ln(1+x) / (x ² + 1) dx
开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
年薪50W+的测试大鸟都在用这个:Jmeter 脚本开发之——扩展函数
Gbase 8A method for reducing the impact on the system by controlling resource usage through concurrency during node replacement of V8 version
[LeetCode]30. Concatenate substrings of all words
Oracle migration MySQL unique index case insensitive don't be afraid