当前位置:网站首页>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);
}
}
边栏推荐
- [oc]- < getting started with UI> -- learning common controls
- 项目连接数据库遇到的问题及解决
- Leetcode: Jianzhi offer 03 Duplicate numbers in array
- What is MySQL? What is the learning path of MySQL
- Niuke winter vacation training 6 maze 2
- LeetCode41——First Missing Positive——hashing in place & swap
- Opencv+dlib realizes "matching" glasses for Mona Lisa
- [OC-Foundation框架]-<字符串And日期与时间>
- An article takes you to understand the working principle of selenium in detail
- LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
猜你喜欢
An article takes you to understand the working principle of selenium in detail
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
opencv+dlib实现给蒙娜丽莎“配”眼镜
Selenium+Pytest自动化测试框架实战(下)
Intel Distiller工具包-量化实现1
postman之参数化详解
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
Advanced Computer Network Review(4)——Congestion Control of MPTCP
Redis之五大基础数据结构深入、应用场景
随机推荐
什么是MySQL?MySql的学习之路是怎样的
LeetCode:498. 对角线遍历
Selenium+Pytest自动化测试框架实战(下)
LeetCode:236. 二叉树的最近公共祖先
LeetCode:162. 寻找峰值
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
To effectively improve the quality of software products, find a third-party software evaluation organization
Selenium+pytest automated test framework practice
Selenium+Pytest自动化测试框架实战
Advanced Computer Network Review(3)——BBR
MySQL uninstallation and installation methods
Leetcode刷题题解2.1.1
UML圖記憶技巧
opencv+dlib实现给蒙娜丽莎“配”眼镜
Intel Distiller工具包-量化实现1
xargs命令的基本用法
LeetCode:498. Diagonal traversal
Notes 01
Leetcode problem solving 2.1.1
Alibaba cloud server mining virus solution (practiced)