当前位置:网站首页>AcWing 2456. Notepad
AcWing 2456. Notepad
2022-07-06 09:10:00 【Easenyang】
Title Description
Initially, there was only one character on a notepad A.
You can do two things with this notebook at a time :
Copy All ( Copy all ) :
You can copy all the characters in this Notepad ( Partial duplication is not allowed ).
Paste ( Paste ) :
You can paste the last character you copied . Given a number n.
You need to use the least number of operations , Print out exactly... In Notepad n individual A.
The output can print out n individual A The minimum number of operations .
Input format
An integer n.
Output format
An integer , Indicates the minimum number of operations .
Data range
1 ≤ n ≤ 1 0 6 1≤n≤10^6 1≤n≤106
Topic link : Notepad
Ideas :
Let's first consider that the input number is a prime number n The situation of : Prime numbers must be copied first 1 Time , Then paste n - 1 Time .( for example 7 Only copy 1 Time , Paste 6 Time to get , You can push it once on the draft book )
So for the case of composite numbers , We can decompose the prime factor , Then keep pasting to get .
for instance :
24 = 22 * 32. Let's copy and paste to get 2, Copy 1 Time , Paste 2 - 1 Time , obtain 22 You have to copy again 1 Time , Paste 2-1 Time , And then put 22 As a whole , Copy 1 Time , Paste 3-1 Time , Copy again 1 Time , Paste 2-1 Time . common 2x2+3x2 = 10 Time
Code :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n = new Scanner(System.in).nextInt();
int res = 0;;
for (int i = 2; i <= n; i++) {
int s = 0; // Look at how many times the prime factor has been used
while (n % i == 0) {
s++;
n /= i;
}
if (s > 0) {
res += i * s;
}
}
System.out.println(res);
}
}
边栏推荐
- LeetCode:41. 缺失的第一个正数
- Detailed explanation of dynamic planning
- CUDA realizes focal_ loss
- Intel distiller Toolkit - Quantitative implementation 1
- [OC-Foundation框架]---【集合数组】
- Advance Computer Network Review(1)——FatTree
- LeetCode:39. 组合总和
- CSP first week of question brushing
- LeetCode:34. Find the first and last positions of elements in a sorted array
- Philosophical enlightenment from single point to distributed
猜你喜欢
Intel Distiller工具包-量化实现2
UML diagram memory skills
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
BN折叠及其量化
Intel distiller Toolkit - Quantitative implementation 3
SimCLR:NLP中的对比学习
IJCAI2022论文合集(持续更新中)
Different data-driven code executes the same test scenario
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Improved deep embedded clustering with local structure preservation (Idec)
随机推荐
What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
Computer graduation design PHP Zhiduo online learning platform
【shell脚本】——归档文件脚本
Pytest之收集用例规则与运行指定用例
Intel Distiller工具包-量化实现3
LeetCode:26. 删除有序数组中的重复项
Leetcode: Sword finger offer 48 The longest substring without repeated characters
LeetCode:162. Looking for peak
[OC-Foundation框架]-<字符串And日期与时间>
【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
Leetcode problem solving 2.1.1
What is an R-value reference and what is the difference between it and an l-value?
pytorch查看张量占用内存大小
Selenium+pytest automated test framework practice (Part 2)
Post training quantification of bminf
什么是MySQL?MySql的学习之路是怎样的
LeetCode:39. 组合总和
五层网络体系结构
CUDA实现focal_loss
MySQL uninstallation and installation methods