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. Windows defender怎么才能彻底关闭?

    据不久前的一项测试表明,Windows系统自带的Windows defender软件在所有参与测试的杀毒安全软件中对win10的运行速度影响最大. 而Win10系统的Windows defender会 ...

  2. yocto project user’s guide

    http://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html 参考手册 http://www.yoctoproject.org/doc ...

  3. python中的__init_subclass__是什么?

    什么是__init_subclass__ class Hook: def __init_subclass__(cls, **kwargs): print("__init_subclass__ ...

  4. 使用browsercookie来管理浏览器cookies

    处理cookie是很繁琐的一件事情,稍微有一点处理不对的话,就不能访问网站,最好的办法就是能操作浏览器cookie,这样是最真实的,在Python中有一个第三方库: browsercookie就是来解 ...

  5. ChromePassword

    # -*- coding: utf-8 -*- 2# @Author : pwf 3 4# @Date : 2019/5/18 22:53 5# Software : PyCharm 6# versi ...

  6. git 版本撤销,回退等

    git checkout -- <file>       #丢弃工作区的修改, 不要省略 -- ,这是只在工作区(work tree)修改了内容,还没有add 到暂存区,此时想撤销修改. ...

  7. mysql优化(上)

    磁盘组成  和  磁盘读取过程 尽量减少 i/o 操作. 表结构设计:(1)三范式 :   原子性(不可拆分).唯一性(不能有完全相同的数据).无冗余性(不能有多余的数据),对于冗余性说明一下:拿订单 ...

  8. .net大文件传输断点续传源码

    IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头. 一. 两个必要响应头Accept-Ranges.ETag 客户端每次提交下载请求时,服务 ...

  9. 【原创】Python3 + Red + PyDev + Eclipse + Subversion + RobotFramework + UI Automator2 + Weditor 构建Web+Mobile 交互式移动App自动化测试环境

    环境搭建步骤: 1. 下载安装Oracle JDK: 安装路径设置为C:\Program Files\Java\jdk1.8.0_152 2. 下载安装Eclipse: 安装路径设置为C:\Eclip ...

  10. C++回调函数、静态函数、成员函数踩过的坑。

    C++回调函数.静态函数.成员函数踩过的坑. 明确一点即回调函数需要是静态函数.原因: 普通的C++成员函数都隐含了一个this指针作为参数,这样使得回调函数的参数和成员函数参数个数不匹配. 若不想使 ...