localp={}functionp.factor(frame)-- Consider calling the parser function #expr-- to simplify a potential mathematical expression?number=tonumber(frame.args[1])ifnumber==nilthenreturn'<strong class="error">Error: input not recognized as a number</strong>'endproductSymbol=frame.args['product']or'·'bold=frame.args['bold']andtruebig=frame.args['big']andtrueserif=frame.args['serif']andtrueprimeLink=frame.args['prime']andtruenumber=math.floor(number)ifnumber<2ornumber>1000000000ornumber==math.hugethenreturn'<strong class="error">خطا: '..number..' خارج از محدوده است.</strong>'endresult=""currentNumber=numberpower=0divisor=2-- Attempt factoring by the value of the divisor-- divisor increments by 2, except first iteration (2 to 3)whiledivisor<=math.sqrt(currentNumber)dopower=0whilecurrentNumber%divisor==0docurrentNumber=currentNumber/divisorpower=power+1end-- Concat result and increment divisor-- when divisor is 2, go to 3. All other times, add 2result=result..powerformat(divisor,power,productSymbol)divisor=divisor+(divisor==2and1or2)endifcurrentNumber~=1thenresult=result..currentNumber..' '..productSymbol..' 'endifcurrentNumber==numberandprimeLinkthenreturn'[[عدد اول|اول]]'endresult=string.sub(result,1,-4)returnformat(result)endfunctionpowerformat(divisor,power,productSymbol)ifpower<1thenreturn''elseifpower==1thenreturndivisor..' '..productSymbol..' 'elsereturndivisor..'<sup>'..power..'</sup> '..productSymbol..' 'endendfunctionformat(numString)ifboldthennumString='<b>'..numString..'</b>'endret=(seriforbig)and'<span 'or''ifserifthenret=ret..'class="texhtml" 'endifbigthenret=ret..'style="font-size:165%" 'endret=ret..((seriforbig)and'>'or'')..numString..((seriforbig)and'</span>'or'')returnretendreturnp