Function: Enter a positive integer that outputs all of its prime number factors (such as 180 prime number factor 2 2 3 3 5) in a small to large order
Detailed Description:
Function Interface Description:
Public String GetResult (long Uldatainput)
Input parameters:
Long uldatainput: A positive integer entered
return value:
String
Enter a description:
Enter a long integer
Output Description:
A factor that outputs all of its prime numbers in a small to large order, separated by a space
Enter an example:
180
Output Example:
2 2 3 3 5
The idea: The breakthrough is to divide the long number by the time it starts at 2 and then loops. Until this long type ==1
The code is as follows:
Import Java.util.Scanner;
public class Hua_6 {public
static void Main (string[] args) {
Scanner sc =new Scanner (system.in);
Long x =sc.nextlong ();
GetResult (x);
}
static void GetResult (long x) {
int i=0;
int k= (int) x;
while (true) {for
(i=2;i<=k;i++) {
if (k%i==0) {
System.out.print (i+ "");
k=k/i;
break;
}
}
if (k==1) {break;}}}}