import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
 
public class HW20141216 {
  static String strCurrentInt = "";
  static int startInt = 0;
  static int currentInt = 0;
  static String OPRATOR_PLUS = "*";
  static Set<Integer> primeSet = new HashSet<Integer>();
  static boolean isPrime = false;
  static String stringPrimeFact = "";
  static BufferedReader br = null;
  
  /*定数*/
  static final int MAX_DIGIT = 15;
  static final String START_COMMENT = "整数を入力してください。";
  static final String WARN_COMMENT = "2以上の整数を入力してください。";
  
  public static void main (String[] args) throws IOException, NumberFormatException {
    try {
      br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println(START_COMMENT);
      readLineAndIntConvert();
      while (!(currentInt >=2)) {
        System.out.println(WARN_COMMENT);
        readLineAndIntConvert();
      }
      startInt = currentInt;
      int workInt = 2;
      makePrimeFactorization (workInt, currentInt);
    } catch (IOException iEx) {
      System.out.println(iEx.toString());
    } catch (NumberFormatException nEx) {
      System.out.println(nEx.toString());
    } finally {
      if (br != null) {
        br.close();
      }
    }
  }

  private static void makePrimeFactorization (int workInt, int currentInt) {
    while (currentInt !=1) {
      if(isPrime(workInt) && currentInt % workInt == 0) {
        currentInt /= workInt;
        stringPrimeFact += workInt + OPRATOR_PLUS;
      } else {
        ++workInt;
      }
    }
    if (stringPrimeFact.length() > 0) {
      stringPrimeFact = stringPrimeFact.substring(0, stringPrimeFact.length() - 1);
      System.out.println(startInt + " = " + stringPrimeFact);
    }
  }

  private static void readLineAndIntConvert() throws IOException, NumberFormatException{
    strCurrentInt = br.readLine();
    currentInt = Integer.parseInt(strCurrentInt);
  }

  private static boolean isPrime (int workInt) {
    if(primeSet.contains(new Integer(workInt))){
      return true;
    }
    for (int i = 2; (double)i <= (double)Math.sqrt(workInt); i++) {
      if(workInt % i == 0) return false;
    }
    primeSet.add(new Integer(workInt));
    return true;
  }
}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS