Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
973 B
4
Indexable
Never
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        boolean isFirst = true;
        int i = 2;
        while(n != 1) {
            if (n % i == 0) {
                int power = 0;
                while(n % i == 0){
                    power++;
                    n /= i;
                }
                if (isFirst && power == 1) {
                    System.out.print(i);
                    isFirst = false;
                }
                else if (isFirst) {
                    System.out.print(i + "^" + power);
                    isFirst = false;
                }
                else if (power == 1)
                    System.out.print("*" + i);
                else
                    System.out.print("*" + i + "^" + power);
                }
            i++;
            }
        }
    }
Leave a Comment