Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:

  1. Copy All: You can copy all the characters present on the notepad (partial copy is not allowed).
  2. Paste: You can paste the characters which are copied last time.

Given a number n. You have to get exactly n 'A' on the notepad by performing the minimum number of steps permitted. Output the minimum number of steps to get n 'A'.

Example 1:

Input: 3
Output: 3
Explanation:
Intitally, we have one character 'A'.
In step 1, we use Copy All operation.
In step 2, we use Paste operation to get 'AA'.
In step 3, we use Paste operation to get 'AAA'.

Note:

  1. The n will be in the range [1, 1000].

Runtime: 4 ms, faster than 73.56% of C++ online submissions for 2 Keys Keyboard.

只能进行copy和past,其实是质数问题。能通过copy和paste达到的一定是合数。

class Solution {
public:
int minSteps(int n) {
if(n == ) return ;
for(int i=; i<n; i++){
if(n % i == ) return minSteps(n/i) + i;
}
return n;
}
};

LC 650. 2 Keys Keyboard的更多相关文章

  1. [LeetCode] 650. 2 Keys Keyboard 两键的键盘

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  2. [leetcode] 650. 2 Keys Keyboard (Medium)

    解法一: 暴力DFS搜索,对每一步进行复制还是粘贴的状态进行遍历. 注意剪枝的地方: 1.当前A数量大于目标数量,停止搜索 2.当前剪贴板数字大于等于A数量时,只搜索下一步为粘贴的状态. Runtim ...

  3. LeetCode 650 - 2 Keys Keyboard

    LeetCode 第650题 Initially on a notepad only one character 'A' is present. You can perform two operati ...

  4. 650. 2 Keys Keyboard复制粘贴的次数

    [抄题]: Initially on a notepad only one character 'A' is present. You can perform two operations on th ...

  5. 650. 2 Keys Keyboard

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  6. 【LeetCode】650. 2 Keys Keyboard 只有两个键的键盘(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 素数分解 日期 题目地址:https://le ...

  7. [LeetCode] 651. 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

  8. [LeetCode] 2 Keys Keyboard 两键的键盘

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  9. [LeetCode] 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

随机推荐

  1. codeforces 576C Points on Plane 相邻两点的欧拉距离

    题意:给出n个点,要求排序后,相邻两点的欧拉距离之和小于等于2.5e9做法:由于0≤ xi, yi ≤ 1e6,所以可以将x<=1000的点分成一份,1000<x<=2000的点分成 ...

  2. Ubuntu18.04安装UHD+GNU Radio后找不到USRP B210解决办法

    一.在终端中输入uhd_usrp_probe,提示USB错误,没有权限. 解决办法: 输入 : sudo uhd_usrp_probe 二.GNU Radio中出现找不到设备,地址为空的错误: 错误原 ...

  3. SpringBoot 上传读取图片 巨坑

    之前自己也做过文件上传,不过存储路径放在那个tomcat服务器路径下,就没遇到什么问题 但前几天在做图片的上传,想把文件放在项目下指定的一个文件夹下,就感觉有点麻烦 修改配置文件 在springboo ...

  4. 创建表空间 ora-01119

    create tablespace user_data logging datafile 'D:\app\Administrator\oradata\orcl\ARCHIVE.dbf' size 50 ...

  5. 抓取腾讯招聘python岗位

    # -*- coding: utf-8 -*- """ @author: Dell Created on Mon Dec 23 17:55:06 2019 "& ...

  6. GIT 工作流程常用用命令大全

    一.Git基本工作流程 1.Git工作区域   2.向仓库中添加文件流程 二.Git初始化及仓库创建和操作 1.Git安装之后需要进行一些基本信息设置 a.设置用户名:git  config -- g ...

  7. gRPC应用实践

    What is RPC? Remote Procedure Call is a high-level model for client-server communication. Assume the ...

  8. Pycharm2019最新激活码

    激活pycharm的方法有很多,一种是使用最新的激活码,另一种是使用破解补丁的方式(可以长期使用) pycharm2019最新激活码: 812LFWMRSH-eyJsaWNlbnNlSWQiOiI4M ...

  9. 鸟哥linux私房菜第6章笔记

    鸟哥linux私房菜第6章笔记 文件权限 修改 chgrp [-R] groupname filename //修改文件所属组 chown [-R] ownername[:groupname] fil ...

  10. 【51nod 1847】奇怪的数学题

    题目描述 给出 N,K ,请计算下面这个式子: \(∑_{i=1}^N∑_{j=1}^Nsgcd(i,j)^k\) 其中,sgcd(i, j)表示(i, j)的所有公约数中第二大的,特殊地,如果gcd ...