当前位置:网站首页>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);
}
}
边栏推荐
- I-BERT
- What are the common processes of software stress testing? Professional software test reports issued by companies to share
- Revit secondary development Hof method calls transaction
- 【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
- 使用标签模板解决用户恶意输入的问题
- 甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
- [MySQL] limit implements paging
- [oc foundation framework] - < copy object copy >
- KDD 2022 paper collection (under continuous update)
- [MySQL] multi table query
猜你喜欢

MongoDB 的安装和基本操作

Redis之Bitmap

Mise en œuvre de la quantification post - formation du bminf
![[OC-Foundation框架]---【集合数组】](/img/b5/5e49ab9d026c60816f90f0c47b2ad8.png)
[OC-Foundation框架]---【集合数组】

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

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

What is MySQL? What is the learning path of MySQL

LeetCode:221. 最大正方形

Intel distiller Toolkit - Quantitative implementation 3

LeetCode:498. Diagonal traversal
随机推荐
[OC foundation framework] - [set array]
Computer graduation design PHP Zhiduo online learning platform
Export IEEE document format using latex
【剑指offer】序列化二叉树
Different data-driven code executes the same test scenario
LeetCode:498. Diagonal traversal
BN folding and its quantification
CSP first week of question brushing
Notes 01
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
AcWing 2456. 记事本
Intel distiller Toolkit - Quantitative implementation 2
Niuke winter vacation training 6 maze 2
MYSQL卸载方法与安装方法
Selenium+Pytest自动化测试框架实战(下)
LeetCode:836. Rectangle overlap
MySQL uninstallation and installation methods
Intel Distiller工具包-量化实现1
[MySQL] multi table query
Tdengine biweekly selection of community issues | phase III