Skip to content

Instantly share code, notes, and snippets.

@FantasticJZI
Created October 17, 2023 03:35
Show Gist options
  • Save FantasticJZI/914584648d2f6e59d525793d4372195f to your computer and use it in GitHub Desktop.
Save FantasticJZI/914584648d2f6e59d525793d4372195f to your computer and use it in GitHub Desktop.
The problem of factoring.
import java.util.Scanner;
public class a010
{
private static int factoring(int input)
{
for(int i=2;i<input;i++)
{
if(input%i==0)
return i;
}
return input;
}
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int input=in.nextInt(),count=0;
int[] element=new int[1000];
while(input!=1)
{
element[count++]=factoring(input);
input/=element[count-1];
}
int time=1;
for(int i=0;i<count;i++)
{
if(i==count-1)
{
if(time!=1)
System.out.println(element[i] + "^" + time);
else
System.out.println(element[i]);
break;
}
if(element[i]==element[i+1])
time++;
else if(element[i]!=element[i+1])
{
if(time!=1)
{
System.out.print(element[i] + "^" + time + " * ");
time = 1;
}
else
System.out.print(element[i] + " * ");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment