import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
 
public class HW20141216 {
  static String strCurrentLong = "";
  static long startLong = 0;
  static long currentLong = 0;
  static String OPRATOR_PLUS = "*";
  static TreeSet<Long> primeSet = new TreeSet<Long>();
  static boolean isToBeChecked = 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 {
    primeSet.add(new Long (2));
    try {
      br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println(START_COMMENT);
      readLineAndLongConvert();
      while (!(currentLong >=2)) {
        System.out.println(WARN_COMMENT);
        readLineAndLongConvert();
      }
      startLong = currentLong;
      long workLong = 2;
      makePrimeFactorization (workLong, currentLong);
    } 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 (long workLong, long currentLong) {
    while (currentLong !=1) {
      if(isToBeChecked(workLong) && currentLong % workLong == 0) {
        currentLong /= workLong;
        stringPrimeFact += workLong + OPRATOR_PLUS;
      } else {
        workLong = workLong > 2 ? workLong + 2 : workLong + 1;
      }
    }
    if (stringPrimeFact.length() > 0) {
      stringPrimeFact = stringPrimeFact.substring(0, stringPrimeFact.length() - 1);
      System.out.println(startLong + " = " + stringPrimeFact);
    }
  }

  private static void readLineAndLongConvert() throws IOException, NumberFormatException{
    strCurrentLong = br.readLine();
    currentLong = Long.parseLong(strCurrentLong);
  }

  private static boolean isToBeChecked (long workLong) {
    if(primeSet.contains(new Long(workLong))){
      return true;
    }
    for (long j :primeSet) {
      if(workLong % j == 0) {
        return false; 
      }else if (workLong % j != 0 && (double)j >= (double)Math.sqrt(workLong)){
        primeSet.add(new Long(workLong));
        return true;
      }
    }
    primeSet.add(new Long(workLong));
    return true;
  }
}

HW20150106

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class HW20150106 extends Applet implements MouseListener,MouseMotionListener {

  ArrayList<Point> points = new ArrayList<Point>();
  Point currentPoint;

  public void init(){
    addMouseListener(this);
    addMouseMotionListener(this);
  }

  public void paint(Graphics g){
    g.setColor(Color.red);
    Point prevPoint;
    if(points.isEmpty()){
      return;
    } else {
      prevPoint = points.get(0);
    }
    for (Point point : points) {
      g.drawLine(point.x, point.y, prevPoint.x, prevPoint.y);
      prevPoint = point;
    }
  }

  // マウスリスナー
  public void mousePressed(MouseEvent ev){
    System.out.println("mouse pressed");
  }
  public void mouseReleased(MouseEvent ev){
    System.out.println("mouse released");
  }
  public void mouseClicked(MouseEvent ev){
    currentPoint = new Point(ev.getX(), ev.getY());
    points.add(currentPoint);
    repaint();
    System.out.println("mouse clicked");
  }
  public void mouseEntered(MouseEvent ev){
    System.out.println("mouse entered");
    setBackground(Color.white);
  }
  public void mouseExited(MouseEvent ev){
    System.out.println("mouse exited");
    setBackground(Color.black);
  }
  public void mouseDragged(MouseEvent ev){
    if(currentPoint == null){
      currentPoint = new Point(ev.getX(), ev.getY());
    }
    int deltaX = ev.getX() - currentPoint.x;
    int deltaY = ev.getY() - currentPoint.y;
    for (Point point : points) {
      point.translate(deltaX, deltaY);
    }
    repaint();
  }
  public void mouseMoved(MouseEvent ev){
  }
}

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