兴业科技编程题
HJ6 质数因子
华为机试中
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()) { long n = in.nextLong(); ArrayList<Long> re = new ArrayList<>(); cal(n,re); for(int i = 0;i<re.size();i++){ System.out.print(re.get(i) + " "); } } } public static void cal(long n,ArrayList<Long> re){ for(long i = 2; i <= Math.sqrt(n); i++) { while(n % i == 0) { re.add(i); n /= i; } } if(n > 1) { re.add(n); } } }