当前位置:网站首页>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 .
边栏推荐
- 登录凭证(cookie+session和Token令牌)
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- Secret script of test case design without leakage -- module test
- JVM memory structure when creating objects
- Gbase 8A OLAP analysis function cume_ Example of dist
- vmware虚拟机PE启动
- [LeetCode]100. 相同的树
- [LeetCode]572. A subtree of another tree
- qt 大文件生成md5校验码
- The create database of gbase 8A takes a long time to query and is suspected to be stuck
猜你喜欢
YOLOv6:又快又准的目标检测框架开源啦
Système de gestion - itclub (II)
[MySQL] database function clearance Tutorial Part 2 (window function topic)
The create database of gbase 8A takes a long time to query and is suspected to be stuck
Go from introduction to actual combat - execute only once (note)
不外泄的测试用例设计秘籍--模块测试
Go from introduction to actual combat -- channel closing and broadcasting (notes)
Experience sharing of meituan 20K Software Test Engineers
Remote invocation of microservices
How to design an elegant caching function
随机推荐
QT base64 encryption and decryption
Luogu p5706 redistributing fertilizer and house water
清华大学教授:软件测试已经走入一个误区——“非代码不可”
GBase 8a OLAP分析函数cume_dist的使用样例
Dynamic refresh mapper
[LeetCode]30. 串联所有单词的子串
大厂常用软件测试面试题三(附答案)
STM32F107+LAN8720A使用STM32cubeMX配置网络连接+tcp主从机+UDP app
熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
[LeetCode]515. 在每个树行中找最大值
记一次List对象遍历及float类型判断大小
百万年薪独家专访,开发人员不修复bug怎么办?
Management system itclub (Part 2)
Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)
Analysis of stone merging
BAT测试专家对web测试和APP测试的总结
Special tutorial - Captain selection game
xpath
C language programming detailed version (learning note 1) I can't understand it after reading, and I can't help it.
深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图