Project Euler 204

by uwi
@see http://projecteuler.net/index.php?section=problems&id=204
♥0 | Line 29 | Modified 2009-06-25 01:28:29 | MIT License
play

ActionScript3 source code

/**
 * Copyright uwi ( http://wonderfl.net/user/uwi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/z9FF
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.getTimer;
    // @see http://projecteuler.net/index.php?section=problems&id=204
    public class Euler204 extends Sprite {
        private var _tf : TextField;
  
        public function Euler204() {
            _tf = new TextField();
            _tf.width = 465;
            _tf.height = 465;
            addChild(_tf);
            
            var s : int = getTimer();
            _tf.appendText(solve(0, N).toString() + "\n");
            var g : int = getTimer();
            _tf.appendText((g - s).toString() + " ms\n");
        }
        
        private const N : int = 1000000000;
//        private const primes : Array = [2, 3, 5];
        private const primes : Array = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
        
        private function solve(p : int, n : int) : int
        {
            if(p == primes.length)return 1;
            
            var sum : int = 0;
            for(var x : int = n;x > 0; x /= primes[p]){
                sum += solve(p + 1, x);
            }
            
            return sum; 
        }
    }
}