#include<iostream>#include<cmath>usingnamespace std;#define maxn 1000000voidfactor(int n,int a[maxn],int b[maxn],int& tot){
int temp, i, now;
temp =(int)(sqrt((double)n)+1);
tot =0;
now = n;for(i =2; i <= temp; i++)if(now % i ==0){
a[++tot]= i;
b[tot]=0;while(now % i ==0){
++b[tot];
now /= i;}}if(now !=1){
a[++tot]= now;
b[tot]=1;}}intmain(){
int n;while(true){
cin >> n;int a[maxn], b[maxn];int tot =0;factor(n, a, b, tot);
cout << n <<" = ";for(int i =1; i <= tot; i++){
for(int j =1; j <= b[i]; j++){
cout << a[i];if(i == tot && j == b[i]) cout << endl;else cout <<" * ";}}}return0;}
JAVA
package demo;import java.util.Scanner;publicclassFactor{
privatestaticint tot =0;privatestaticvoidfactor(int n,int[] a,int[] b){
tot =0;int i, now;int temp =(int)(Math.sqrt((double)(n)))+1;
now = n;for(i =2; i <= temp; i++)if(now % i ==0){
a[++tot]= i;
b[tot]=0;while(now % i ==0){
++b[tot];
now /= i;}}if(now !=1){
a[++tot]= now;
b[tot]=1;}}publicstaticvoidmain(String[] args){
Scanner input =newScanner(System.in);int n;while(true){
n = input.nextInt();int[] a =newint[n];int[] b =newint[n];factor(n, a, b);
System.out.print(n +" = ");for(int i =1; i <= tot; i++){
for(int j =1; j <= b[i]; j++){
System.out.print(a[i]);if(i == tot && j == b[i]) System.out.println();else System.out.print(" * ");}}}}}
Python
import numpy as np
deffactor(n, a, b, tot_):
tot =0
temp =int(np.sqrt(n)+1)
now = n
for i inrange(2, temp +1):if now % i ==0:
tot +=1
a[tot]= i
while now % i ==0:
b[tot]+=1
now /= i
if now !=1:
tot +=1
a[tot]=int(now)
b[tot]=1
tot_[0]= tot
if __name__ =='__main__':whileTrue:
n =int(input())
a =[0for i inrange(n +1)]
b =[0for i inrange(n +1)]
tot =[0]
factor(n, a, b, tot)
num = tot[0]print(num,"= ", end='')for i inrange(1, num +1):for j inrange(0, b[i]):print(a[i], end='')if i == num and j == b[i]-1:print()else:print(" * ", end='')