#! /usr/local/bin/perl

$|=1; # set output unbuffered

print 
     "%Form top topLevel\n"
    ."%Text input top editType edit width 200\n"
    ."%action input override {<Key>Return: exec(echo [gV input string])}\n"
    ."%Label result top label {} width 200 fromVert input\n"
    ."%Command quit top fromVert result callback quit\n"
    ."%Label info top fromVert result fromHoriz quit label {} borderWidth 0 width 150\n"
    ."%realize\n";

while(<STDIN>) {
    chop;

    if (/^\d+$/) {
	print "%sV info label {thinking ...}\n"; 
	$starttime = time;
	for ($d=2,@result=(); $d <= $_; $d++) {
	    while (!($_ % $d)) {
		unshift(@result,$d);
		$_ /= $d;
	    }
	}
	print 
	    "%sV result label {" .join('*',@result). "}\n" 
	   ."%sV info label {".(time-$starttime)." seconds}\n" ; 
    } else {
	print "%sV info label {invalid input}\n"; 
    }
}

