题解 | #质数因子#

质数因子

https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
	long num = sc.nextLong();
	for (long i = 2; i <= (long) Math.sqrt(num); i++) {
		while (num % i == 0) {
		  System.out.print(i + " ");
		  num /= i;
		}
	}
	if (num > 2) {
		  System.out.print(num);
	}
}

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务