Decompose a positive integer into the product of its prime factors. For example, input 90, output 90=2 3 3*5.
Please do not change the original structure and code of the program, complete the program, and get the correct running result.
Input: 90
Output: 90=2 3 3*5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);//定义读取数据对象reader
int n;
n=reader.nextInt(); //读取一个整数
Main pf=new Main();
pf.printPrimeFactor(n);
}
void printPrimeFactor(int n){ //求整数n的质因子,按按要求输出
}
int isPrimeNumber(int n){
}
}
0 Answer
the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > the following is a complete Java code, can be a positive integer is decomposed into the product of prime factors, and the output according to the requirement:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);//定义读取数据对象reader
int n;
n = reader.nextInt(); //读取一个整数
Main pf = new Main();
pf.printPrimeFactor(n);
}
void printPrimeFactor(int n) { //求整数n的质因子,按要求输出
System.out.print(n + "="); //输出原数n
int i = 2; //从2开始寻找因子
while (i <= n) {
if (n % i == 0) { //如果n能够被i整除
System.out.print(i); //输出i
n /= i; //将n除以i,以便继续寻找因子
if (n != 1) { //如果n不等于1,则继续输出乘号
System.out.print("*");
}
} else { //否则i加1
i++;
}
}
}
int isPrimeNumber(int n) {
if (n <= 1) { //小于等于1的数不是质数
return 0;
}
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) { //如果能够被整除,不是质数
return 0;
}
}
return 1; //是质数
}
}
The program runs as follows:
Input:
90
Output:
90=2*3*3*5
This answer quotes ChatGPT
Try this code
import java.util.Scanner;
public class Main {
csharp
Copy code
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);//定义读取数据对象reader
int n;
n = reader.nextInt(); //读取一个整数
Main pf = new Main();
pf.printPrimeFactor(n);
}
void printPrimeFactor(int n) { //求整数n的质因子,按按要求输出
System.out.print(n + "=");
int i = 2;
while (i <= n) {
if (n % i == 0) {
System.out.print(i);
n = n / i;
if (n != 1) {
System.out.print("*");
}
} else {
i++;
}
}
}
int isPrimeNumber(int n) {
if (n <= 1) {
return 0;
}
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
}
This answer is quoted from ChatGPT
public class Main {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);//定义读取数据对象reader
int n;
n=reader.nextInt(); //读取一个整数
Main pf=new Main();
pf.printPrimeFactor(n);
}
void printPrimeFactor(int n){ //求整数n的质因子,按按要求输出
int i=2;
System.out.print(n+"=");
while(i<=n){
if(isPrimeNumber(i)==1 && n%i==0){
System.out.print(i);
n=n/i;
if(n!=1){
System.out.print("*");
}
}else{
i++;
}
}
System.out.println();
}
int isPrimeNumber(int n){
int flag=1;
for(int i=2;iif(n%i==0){
flag=0;
break;
}
}
return flag;
}
}
这家伙很懒,什么都没留下...