Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 11.
- function IsPrimeNumber(Number)
- local X, Y
- Number = math.floor(Number)
- if (Number < 1) then return(false) end
- for X = 0, (Number - 1), 1 do
- for Y = 0, (Number - 1), 1 do
- if (X * Y == Number) then return(false) end
- end
- end
- return(true)
- end
- print(IsPrimeNumber(11))
- 12.
- function GreatestCommonDivisor(VarA,VarB)
- local Greater, Smaller, I
- local Result = nil
- Greater = math.max(VarA,VarB)
- Smaller = math.min(VarA,VarB)
- for I = 1, Greater, 1 do
- if (Greater % I == 0) and (Smaller % I == 0) then
- Result = I
- end
- end
- return(Result)
- end
- print(GreatestCommonDivisor(441,84))
- 13.
- function Coprime(VarA,VarB)
- local Greater, Smaller, I
- local Result = nil
- Greater = math.max(VarA,VarB)
- Smaller = math.min(VarA,VarB)
- for I = 1, Greater, 1 do
- if (Greater % I == 0) and (Smaller % I == 0) then
- Result = I
- end
- end
- if (Result == 1) then return(true) end
- return(false)
- end
- print(Coprime(14,15))
- 18.
- function PrimeList(n)
- local I
- local List = {}
- local function IsPrime(Number)
- local X, Y
- Number = math.floor(Number)
- if (Number < 1) then return(false) end
- for X = 0, (Number - 1), 1 do
- for Y = 0, (Number - 1), 1 do
- if (X * Y == Number) then return(false) end
- end
- end
- return(true)
- end
- for I = 2, n, 1 do
- if IsPrime(I) then table.insert(List,I) end
- end
- return(List)
- end
- print(table.concat(PrimeList(10)," "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement