当前位置:网站首页>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);
}
}
边栏推荐
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- 数字人主播618手语带货,便捷2780万名听障人士
- Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
- Pytest's collection use case rules and running specified use cases
- Advanced Computer Network Review(4)——Congestion Control of MPTCP
- Super efficient! The secret of swagger Yapi
- I-BERT
- Mise en œuvre de la quantification post - formation du bminf
- Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
- [Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
猜你喜欢
Compétences en mémoire des graphiques UML
[OC-Foundation框架]--<Copy对象复制>
Pytest之收集用例规则与运行指定用例
Export IEEE document format using latex
Problems encountered in connecting the database of the project and their solutions
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
Intel distiller Toolkit - Quantitative implementation 3
[OC]-<UI入门>--常用控件的学习
不同的数据驱动代码执行相同的测试场景
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
随机推荐
Redis之性能指标、监控方式
使用latex导出IEEE文献格式
Redis之五大基础数据结构深入、应用场景
Nacos 的安装与服务的注册
Improved deep embedded clustering with local structure preservation (Idec)
在QWidget上实现窗口阻塞
What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
Ijcai2022 collection of papers (continuously updated)
[sword finger offer] serialized binary tree
【shell脚本】——归档文件脚本
自定义卷积注意力算子的CUDA实现
LeetCode:394. String decoding
不同的数据驱动代码执行相同的测试场景
LeetCode:41. 缺失的第一个正数
随手记01
Intel Distiller工具包-量化实现1
[oc]- < getting started with UI> -- learning common controls
项目连接数据库遇到的问题及解决
CSP first week of question brushing
AcWing 2456. 记事本