算法提高 ADV-223 8-1因式分解
来源:互联网 发布:中经网数据库账号 编辑:程序博客网 时间:2024/05/16 08:49
问题描述
设计算法,用户输入合数,程序输出若个素数的乘积。例如,输入6,输出2*3。输入20,输出2*2*5。
样例
与上面的样例输入对应的输出。
例:
例:
数据规模和约定
输入数据中每一个数在int表示范围内。
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int num = scanner.nextInt();devide(num);}private static void devide(int num) {StringBuffer buffer = new StringBuffer();devide(buffer,num,2);System.out.println(buffer.toString());}private static void devide(StringBuffer buffer, int num, int start) {boolean flag = false;int temp = num;for (int i = start; i <= Math.sqrt(num); i++) {if(num % i == 0){buffer.append(i+"*");temp = num / i;start = i;flag = true;break;}}if(flag){devide(buffer,temp,start);} else {buffer.append(temp);}}}
阅读全文
0 0
- 算法提高 ADV-223 8-1因式分解
- 蓝桥杯 ADV-223 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 算法提高——8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- [蓝桥杯]算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解(Java解题)
- 算法提高 ADV-230 12-1三角形
- 算法提高 ADV-222 7-2求arccos值
- 求身份证号末位
- IgH Master 1.5.2 Documentation 中文版
- ng-repeat设置第一个元素为默认样式,点击其余元素切换样式
- 关于springmvc执行的流程和处理过程分析
- 算法提高 ADV-223 8-1因式分解
- 博客应增加功能
- 浅谈单片机、ARM和DSP的异同
- markdown
- celery初级教程(二)
- bzoj 2111(Lucas定理+递推)
- 神经单元阀函数的选择
- PHP 7 新特性(完结篇)
- 死锁的定义、产生原因、必要条件和处理方法