Want to Calculate Least common multiple (LCM) and Greatest common divisor (GCD)

I dont know much about scripting.
Found some scripts in adress below and other places but dont know how to use them.
should i run it with event or have to make a plugin with it?
Can anybody help me about this.

https://www.w3resource.com/javascript-exercises/javascript-math-exercise-10.php
All the math needed to calculate the GCD and LCM can be done in events. Do you need a plugin specifically?
All the math needed to calculate the GCD and LCM can be done in events. Do you need a plugin specifically?

Not really need plugin. i checked wikipedia pages for GCD and LCM formulas, but it is too much complicated to do it with events for me. should i focus on eventing? i dont prefer somebody to make my own work but be pleased if you help about it.
You can make it in the script command of events, if using the math event commands would too troublesome
Taking the formula from the link you first gave for the Greatest Common Divisor
Code:
while(y) {
    var t = y;
    y = x % y;
    x = t;
}
return x;

Each line in that formula is almost one-for-one with event commands. If you know how to use "Control Variables" event command, then you should be able to understand what these event commands are doing. I put a comment of the formula that you provided before it's corresponding event command.

Spoiler: event commands
◆Text:None, Window, Bottom
: :Input the first number:
◆Input Number:Number1 (x), 3 digits
◆Text:None, Window, Bottom
: :Input the second number:
◆Input Number:Number2 (y), 3 digits
◆Comment:while(y)
◆Loop
◆If:Number2 (y) = 0
◆Break Loop
◆
:End
◆Comment:var t = y;
◆Control Variables:#0011 temp (t) = Number2 (y)
◆Comment:y = x % y
◆Control Variables:#0010 Number2 (y) = Number1 (x)
◆Control Variables:#0010 Number2 (y) %= temp (t)
◆Comment:x = t;
◆Control Variables:#0009 Number1 (x) = temp (t)
◆
:Repeat Above
◆Comment:return x;
◆Text:None, Window, Bottom
: :The Greatest Common Divisor is \v[9]

upload_2019-7-26_19-50-3.png
I meneged to make this with eventing, thanks for your attention and help. i ll give you a credit in my project Aloe Guvner 🤘
Sounds good, no need to credit me. Hopefully you can apply the same concepts to the Lowest Common Multiple

Original thread: https://forums.rpgmakerweb.com/threads/want-to-calculate-least-common-multiple-lcm-and-greatest-common-divisor-gcd.111479/