求出区间[a,b]中所有整数的质因数分解。(Java)(转载)

import java.util.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int i=a; i<=b; i++)
        {
            if (i >= 3)
            {
                String m = "";
                int k = 2;
                int j = i;
                while (j != k) 
                {
                    if (j % k == 0) 
                    {
                        m = m + k + "*";
                        j = j / k;
                    }
                    else if (j % k != 0) 
                    {
                        k++;
                    }
                }
                m = m + k;
                System.out.println(i + "=" + m);
            }
            else 
            {
                System.out.println(i + "=" + i);
            }
        }
    }
}

转载:https://blog.csdn.net/m0_38046610/article/details/79660480

上一篇:背包问题


下一篇:实现一个函数用来判断字符串是否表示数值