蓝桥杯 分解质因数

问题描述
  求出区间[a,b]中所有整数的质因数分解。
输入格式
  输入两个整数a,b。
输出格式
  每行输出一个数的分解,形如k=a1*a2*a3...(a1<=a2<=a3...,k也是从小到大的)(具体可看样例)
样例输入
3 10
样例输出
3=3
4=2*2
5=5
6=2*3
7=7
8=2*2*2
9=3*3
10=2*5
提示
  先筛出所有素数,然后再分解。
数据规模和约定
  2<=a<=b<=10000

 1 import java.util.Scanner;
 2 
 3 /**
 4  * @author 宗远
 5  *
 6  * 2017年3月11日
 7  */
 8 public class Test__32 {
 9     public static void main(String[] args) {
10         Scanner sc = new Scanner(System.in);
11         int a = sc.nextInt();
12         int b = sc.nextInt();
13         String str = "";
14         int s = 0;
15         for(int i=a; i<=b; i++){
16                 str = i+"=";
17                 s = i;
18             for(int j=2; j<s; j++){
19                 if(s%j==0){
20                     s = s/j;
21                     str +=j+"*";
22                     j--;
23                 }
24             }
25             System.out.println(str+s);
26         }
27     }
28 }
原文地址:https://www.cnblogs.com/czy960731/p/6670766.html