45 lines
861 B
Java
45 lines
861 B
Java
package LanQiaoOJ;
|
||
|
||
import java.util.Scanner;
|
||
|
||
/*
|
||
* 给定一个数字N,请你求出它的所有质因子。
|
||
输入描述
|
||
输入仅一行包含为一个整数N。
|
||
1≤W≤10^12。*/
|
||
public class 求解质因子 {
|
||
|
||
public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
long n=sc.nextLong();
|
||
for(long i=2;i<n/i;i++) {
|
||
//判断是否为质因子
|
||
if(n%i==0) {
|
||
System.out.print(i+" ");
|
||
//将n除尽
|
||
while(n%i==0)n/=i;
|
||
}
|
||
}
|
||
if(n>1)
|
||
System.out.print(n);
|
||
}
|
||
}
|
||
/*此方法蓝桥OJ上无法通过,超时——暴力破解
|
||
* public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
long n=sc.nextLong();
|
||
|
||
for(long i=2;i<n;i++) {
|
||
if(n%i==0&&check(i)) {
|
||
System.out.print(i+" ");
|
||
}
|
||
}
|
||
}
|
||
static Boolean check(long x) {
|
||
for(long i=2;i<=x/i;i++) {
|
||
if(x%i==0)
|
||
return false;
|
||
}
|
||
return true;
|
||
}*/
|