NYIST 708 ones java
来源:互联网 发布:成都工业学院软件 编辑:程序博客网 时间:2024/04/29 20:25
- 输入
- There are multiple test cases. Each case contains only one line containing a integer N
- 输出
- For each case, output the minimal number of 1s you need to get N.
- 样例输入
210
- 样例输出
2
7
使用单组数据进行测试
import java.util.Scanner;/** * * @author admin *描述 *Given a positive integer N (0<=N<=10000), you are to find an expression equals to N *using only 1,+,*,(,). 1 should not appear continuously, i.e. 11+1 is not allowed. *输入 *There are multiple test cases. Each case contains only one line containing a integer N *输出 *For each case, output the minimal number of 1s you need to get N. *样例输入 *2 *10 *样例输出 *2 *7 */public class Ones {public static void main(String[] args) {Scanner input=new Scanner(System.in);int n=input.nextInt();input.close();System.out.println(computer(n, 2));}public static int computer(int n,int m){for (int i = m; i < n/2; i++) {if(n%i==0){return i+computer(n/i, i);}}return n;}}
0 0
- NYIST 708 ones java
- NYIST 708 ones
- nyist
- nyoj 708 ones
- NYOJ 708 ones
- NYOJ 708 ones
- Nyoj 708 Ones
- NYOJ 708 ones
- ones(nyoj 708)
- Ones
- Ones
- Ones
- ones
- ones
- ones
- leetcode485 Max Consecutive Ones Java
- Java 大数的几道题目 nyist
- nyoj-708 ones【线性dp】
- 合并石子
- 在VMware下安装Ubuntu并部署Hadoop1.2.1分布式环境
- 高手速成android开源项目【tool篇】
- 表单提交数据
- Android开源项目发现---TextView,Button篇(持续更新)
- NYIST 708 ones java
- Ubuntu 14.04中如何打开root账户
- arm网站
- 最大流Dinic模板
- 高手速成android开源项目【项目篇】
- OCP 1Z0 051 10
- 高手速成android开源项目【developer篇】
- 高手速成android开源项目【blog篇】
- 特征选择(二)-聚类变换