当前位置:网站首页>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);
}
}
边栏推荐
- ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
- MYSQL卸载方法与安装方法
- Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
- LeetCode:836. 矩形重叠
- LeetCode:39. Combined sum
- What are the common processes of software stress testing? Professional software test reports issued by companies to share
- SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
- LeetCode:836. Rectangle overlap
- Compétences en mémoire des graphiques UML
- [OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
猜你喜欢

甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求

SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date

opencv+dlib实现给蒙娜丽莎“配”眼镜

Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges

MYSQL卸载方法与安装方法

Selenium+pytest automated test framework practice (Part 2)

What is MySQL? What is the learning path of MySQL

LeetCode:236. The nearest common ancestor of binary tree
![[oc]- < getting started with UI> -- learning common controls](/img/2c/d317166e90e1efb142b11d4ed9acb7.png)
[oc]- < getting started with UI> -- learning common controls

Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
随机推荐
LeetCode:34. 在排序数组中查找元素的第一个和最后一个位置
Problems encountered in connecting the database of the project and their solutions
力扣每日一题(二)
What is an R-value reference and what is the difference between it and an l-value?
IJCAI2022论文合集(持续更新中)
[OC-Foundation框架]--<Copy对象复制>
Nacos 的安装与服务的注册
LeetCode:498. 对角线遍历
Post training quantification of bminf
Pytorch view tensor memory size
Advanced Computer Network Review(5)——COPE
LeetCode:124. 二叉树中的最大路径和
Revit secondary development Hof method calls transaction
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
MongoDB 的安装和基本操作
如何正确截取字符串(例:应用报错信息截取入库操作)
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
Leetcode: Jianzhi offer 03 Duplicate numbers in array
什么是MySQL?MySql的学习之路是怎样的
Export IEEE document format using latex