Created
August 14, 2012 17:46
-
-
Save disjukr/3351186 to your computer and use it in GitHub Desktop.
factorization & isPrime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//정수의 인수분해 | |
function factorization( a:int ):Array | |
{ | |
var primes:Array = []; | |
var factor:int = 2; | |
if( a<2 ) return [ a ]; | |
while( a>1 ) | |
{ | |
while( a%factor ) ++factor; | |
primes.push( factor ); | |
a /= factor; | |
} | |
return primes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//정수의 소수판별 | |
function isPrime( a:int ):Boolean | |
{ | |
var sqrt:int = Math.sqrt( a ); | |
if( a<2 ) return false; | |
for( var i:int=2; a%i&&i<=sqrt; ++i ); | |
return sqrt+1 == i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment