当前位置:网站首页>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);
}
}
边栏推荐
- 【图的三大存储方式】只会用邻接矩阵就out了
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- LeetCode:394. String decoding
- Simclr: comparative learning in NLP
- 【每日一题】搬运工 (DFS / DP)
- Leetcode: Sword finger offer 48 The longest substring without repeated characters
- 在QWidget上实现窗口阻塞
- LeetCode:236. 二叉树的最近公共祖先
- [text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
- UML圖記憶技巧
猜你喜欢

使用latex导出IEEE文献格式

Intel distiller Toolkit - Quantitative implementation 3

An article takes you to understand the working principle of selenium in detail

Opencv+dlib realizes "matching" glasses for Mona Lisa

【剑指offer】序列化二叉树

Pytest参数化你不知道的一些使用技巧 /你不知道的pytest

I-BERT

不同的数据驱动代码执行相同的测试场景

Advanced Computer Network Review(5)——COPE

多元聚类分析
随机推荐
LeetCode:221. Largest Square
Pytest之收集用例规则与运行指定用例
What is MySQL? What is the learning path of MySQL
go-redis之初始化连接
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
MYSQL卸载方法与安装方法
[OC-Foundation框架]--<Copy对象复制>
随手记01
MongoDB 的安装和基本操作
Mise en œuvre de la quantification post - formation du bminf
LeetCode:673. Number of longest increasing subsequences
KDD 2022论文合集(持续更新中)
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
Computer graduation design PHP Zhiduo online learning platform
Multivariate cluster analysis
opencv+dlib实现给蒙娜丽莎“配”眼镜
UML圖記憶技巧
LeetCode:836. 矩形重叠
[OC-Foundation框架]-<字符串And日期与时间>
LeetCode:剑指 Offer 03. 数组中重复的数字