In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ただの素因数分解

素因数分解。
Get Adobe Flash player
by Susisu 24 Oct 2010
    Embed
///べっ別にあんたのために素因数分解してるわけじゃ
package {
    import flash.display.Sprite;
    import flash.text.*;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            var input:TextField=new TextField();
            input.width=120;
            input.height=16;
            input.type=TextFieldType.INPUT;
            input.border=true;
            addChild(input);
            
            var output:TextField=new TextField();
            output.width=260;
            output.height=16;
            output.type=TextFieldType.INPUT;
            output.border=true;
            output.x=170;
            addChild(output);
            
            var button:Sprite=new Sprite();
            var eq:TextField=new TextField();
            eq.htmlText="<p align='center'>=</p>";
            eq.width=50;
            eq.height=16;
            eq.border=true;
            button.addChild(eq);
            button.x=120;
            addChild(button);
            button.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void{output.text=prime(parseInt(input.text));});
            
        }
        public function prime(n:uint):String{
            if(n==0)return "0";
            var a:Array=new Array();
            var i:int=2;
            while(n!=1){
                if(n%i==0){
                    n/=i;
                    a.push(i);
                }else i++;
            }
            var l:int=a.length;
            var s:String="";
            var c:int=1;
            for(i=0;i<l;i++){
                if(i>0){
                    if(a[i-1]!=a[i]){
                        if(c>1){
                            s+="^"+c;
                            c=1;
                        }
                        s+="*"+a[i];
                    }
                    else c++;
                }
                else s+=a[i];
            }
            if(c>1)s+="^"+c;
            return s;
        }
    }
}