package com.ljq.base; /** * 90 = 2*3*3*5 * * @author ljq * @version 1.0 * @since 1.0 */ public class Factorization { public static void factorization(int n) { StringBuilder sb = new StringBuilder(); if (n == 0) { System.out.println(0); } for (int i = 2; i <= n; i++) { while (n != 0) { if (n % i == 0) { n = n / i; sb.append(i).append("*"); } else { break; } } } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } public static void main(String[] args) { factorization(5); } }
package com.ljq.base; /** * 有一对兔子,从出生后第3个月起每个月都生一对兔子, * 小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? * 1 = 1 * 2 = 1 * 3 = 1+ 1 =2 * 4 = 1 + 1+ 1=3 * 5 = 1+ 1+ 1+ 1+ 1=5 * 6 = 1+ 1+ 1+ 1+ 1 + 1 + 1 + 1 = 8 * 7 = 1+ 1+ 1+ 1+ 1 + 1 + 1 + 1+1+1+ 1+ 1+ 1 = 13 * F(n) = F(n-1)+F(n+1);(n>2,F(1)=1,F(2)=1); * @author ljq * @version 1.0 * @since 1.0 */ public class RabbitProblem { public static int getRabbitNumByMonth(int n) { return rabbitNum(n); } private static int rabbitNum(int n) { if (n <= 2) { return n == 0 ? 0 : 1; } return rabbitNum(n - 1) + rabbitNum(n - 2); } public static void main(String[] args) { System.out.println(getRabbitNumByMonth(66)); } }
package com.ljq.base; /** * 打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。 * 例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方 * * @author ljq * @version 1.0 * @since 1.0 */ public class Narcissus { public static void printNarcissus() { for (int i = 100; i < 1000; i++) { int bit = i % 10; int ten = (i / 10) % 10; int hundred = i / 100; int sum = cube(hundred) + cube(ten) + cube(bit); if (i == sum) { System.out.print(i + " "); } } } private static int cube(int i) { return i * i * i; } public static void main(String[] args) { printNarcissus(); } }
/** * 猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾, * 又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。 * 以后每天早上都吃了前一天剩下的一半零一个。 * 到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少 * * r =n-(n/2+1) n=2(r+1) ---> n=2(1+1)=4 * 9 4 - (4/2+1) * 10 1 * @author ljq * @version 1.0 * @since 1.0 */ public class MonkeyEatPeaches { public static int eat(int day, int peachs){ int n=peachs; for(int i=0; i<day; i++){ n = 2*(n+1); } return n; } public static void main(String[] args){ System.out.println(eat(10, 1)); } }
相关推荐
计算机算法基础题目归并分类上机答案要的速度看绝对正确啊
盘点一道Python基础实现代数运算的基础题目全文共2页,当前为第1页。盘点一道Python基础实现代数运算的基础题目全文共2页,当前为第1页。盘点一道Python基础实现代数运算的基础题目 盘点一道Python基础实现代数运算...
C语言程序设计基础,里面有一些基础的题目,或许对你有帮助
大学计算机基础题目 基础知识 大学计算机
盘点Python列表的一道基础题目全文共3页,当前为第1页。盘点Python列表的一道基础题目全文共3页,当前为第1页。盘点Python列表的一道基础题目 盘点Python列表的一道基础题目全文共3页,当前为第1页。 盘点Python列表...
python最全基础题目及答案6全文共3页,当前为第1页。python最全基础题目及答案6全文共3页,当前为第1页。python最全基础题目及答案6 python最全基础题目及答案6全文共3页,当前为第1页。 python最全基础题目及答案6...
C语言基础题目2C语言基础题目2
python最全的基础题目及答案3全文共12页,当前为第1页。python最全的基础题目及答案3全文共12页,当前为第1页。python最全的基础题目及答案3 python最全的基础题目及答案3全文共12页,当前为第1页。 python最全的...
计算机基础题目2
计算机基础题目1
727_基础题目集合,727_基础题目集合
大学计算机基础题目及答案集成 办公软件题目word ppt excel
计算机基础题目2答案
计算机基础题目1答案
文件为HTML基础题目,题目如下,欢迎下载,3-1《七步诗》3-2制作Google Logo效果3-3《关山月》3-4通配符选择器3-5CSS字体样式属性3-6春天3-7你若安好便是晴天3-8CSS层叠性3-9CSS优先级3-10制作新浪博客效果
C++的基础题目,面试笔试必备,c++基础题目大全,笔试大全
指数对数运算经典基础题目题目.doc
java ·基础题目 刚学Java的可以做做。。。
C语言基础题目及答案,内容均为基础性需要掌握的内容
基础题目实验报告1