HJ6质数因子
1 import java.util.Scanner; 2 3 /** 4 * @author: yekai <br/> 5 * Date: 2021/11/15:21:28 <br/> 6 * Description:HJ6质数因子 7 * 给出一个数,求他的质数因子 8 */ 9 public class HJ6 { 10 public static void main(String[] args) { 11 Scanner sc = new Scanner(System.in); 12 //定义一个long数 13 long a = sc.nextLong(); 14 long k = (long)Math.sqrt(a); 15 for(long i = 2;i<= k;i++) { 16 while (a % i == 0){ 17 System.out.print(i + " "); 18 a /= i; 19 } 20 21 } 22 //没有这句话的话会导致测试用例一个不通过 23 System.out.println(a == 1 ? "": a+" "); 24 } 25 }