# mIRC functions - \$fact (factorise) , \$lcm , \$hcf and \$isprime

### By manish17xxx on Jun 12, 2017

Here are a few functions that I created which will probably help you out.

Usage:-
\$isprime(number) - will return \$true if it is prime and \$false if it is not prime.
\$fact(number) - will display result after factorising the number , for example, \$fact(32) will return 2^5
\$hcf(numbers) - will return HCF of a group of numbers, for example, \$hcf(68 51 85) will return 17
\$lcm(numbers) - will return LCM of a group of numbers, example : \$lcm(32 64 96) will return 192

``````############################################################
##      mIRC functions for factorisation , lcm , hcf , isprime    ( \$fact , \$isprime , \$hcf , \$lcm)      ##
##       Version: 1.0              ##
##       By: manish17               ##
##       irc.lunarirc.net   #LunarIRC #LunarGames   User - manish
Follow my blog : https://manishsnippets.blogspot.com ##
############################################################
alias fact {
if (\$isprime(\$1)) || (\$1 == 1) { return \$1 \$+ ¹ }
elseif ( \$1 == 0 ) { return - }
elseif ( \$1 < 0 ) { return N/A }
set %number \$1
while ( %number > 1 ) {
set %power 0
set %no 2
set %max \$calc( %number / 2)
while ( %no <= %max ) {
if ( %no // %number ) {
set %number \$calc( %number / %no )
inc %power
}
else {
if ( %power == 0 ) { inc %no }
else {
inc %no
set %power 0
}
}
}
}
if (\$isid) { return \$replace(%answer,^0,⁰,^1,¹,^2,²,^3,³,^4,⁴,^5,⁵,^6,⁶,^7,⁷,^8,⁸,^9,⁹) }
}

alias isprime {
if ( \$round(\$1,0) != \$1 ) || (\$1 < 2) return \$null
if (\$1 < 4) return \$true
if (\$1 > 3) {
if ( 2 // \$1 ) { return \$false }
var %x = 1
var %y = \$floor(\$sqrt(\$1))
while (%x < %y) {
inc %x 2
if (%x // \$1) return \$false
}
return \$true
}
}

alias hcf {
set %numbers \$sorttok(\$1-,32,n)
set %numtok \$numtok(%numbers,32)
set %first \$gettok(%numbers,1,32)
if (%first < 0 ) { return N/A }
elseif (%first == 0 ) { return 0 }
set %x 1
while ( %x <= %first ) {
set %omg 1
set %y 0
while ( %omg <= %numtok ) {
set %curtok \$gettok(%numbers,%omg,32)
if ( %x // %curtok ) {
inc %y
if ( %y == %numtok) { set %hcf %x }
}
inc %omg
}
inc %x
}
if (\$isid) { return %hcf }
}

alias lcm {
set %lcm 1
set %numbersare \$sorttok(\$1-,32,n)
set %first \$gettok(%numbersare,1,32)
if (%first < 0 ) { return N/A }
elseif (%first == 0 ) { return 0 }
elseif ( \$numtok(%numbersare,32) == 1 ) { return %numbersare }

while ( \$numtok(%numbersare,32) > 1 ) {
set %a \$gettok(%numbersare,1,32)
set %b \$gettok(%numbersare,2,32)
set %c \$hcf(%a %b)
set %lcm \$calc( %a * %b / %c )
set %numbersare %lcm %numbersare
set %numbersare \$deltok(%numbersare,2-3,32)
}
return %lcm
}
``````