当前位置:网站首页>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 .
边栏推荐
- [LeetCode]508. 出現次數最多的子樹元素和
- I think I should start writing my own blog.
- Use Fiddler to simulate weak network test (2g/3g)
- Bit. Store: long bear market, stable stacking products may become the main theme
- This set of steps for performance testing using JMeter includes two salary increases and one promotion
- Go from introduction to actual combat -- channel closing and broadcasting (notes)
- vmware虚拟机PE启动
- List of language weaknesses --cwe, a website worth learning
- xpath
- 软件测试自动化测试之——接口测试从入门到精通,每天学习一点点
猜你喜欢

【MySQL】数据库函数通关教程下篇(窗口函数专题)

At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions

Stm32f107+lan8720a use stm32subemx to configure network connection +tcp master-slave +udp app

YOLOv6:又快又准的目标检测框架开源啦

Go from introduction to practice -- coordination mechanism (note)

Remote invocation of microservices
How to design an elegant caching function
![[leetcode] dynamic programming solution split integer i[silver fox]](/img/18/8dc8159037ec1262444db8899cde0c.png)
[leetcode] dynamic programming solution split integer i[silver fox]

Simulink method for exporting FMU model files

STM32F107+LAN8720A使用STM32cubeMX配置网络连接+tcp主从机+UDP app
随机推荐
Example of using gbase 8A OLAP function group by grouping sets
Go from introduction to practice -- coordination mechanism (note)
鲜为人知的mysql导入数据
Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)
[LeetCode]100. Same tree
[leetcode] 508. Élément de sous - arbre le plus fréquent et
[Sword Offer II]剑指 Offer II 029. 排序的循环链表
Summary of Web testing and app testing by bat testing experts
Interview question 3 of software test commonly used by large factories (with answers)
Dynamic refresh mapper
大厂常用软件测试面试题三(附答案)
Null pointer exception
[LeetCode]572. A subtree of another tree
豆沙绿保护你的双眼
BAT测试专家对web测试和APP测试的总结
GBase 8a OLAP分析函数cume_dist的使用样例
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
I think I should start writing my own blog.
How to do function test well? Are you sure you don't want to know?
[LeetCode]508. 出現次數最多的子樹元素和