Números Primos - 01

Cria uma lista dos 100 primeiros números primos
Create a list with the first's 100 prime numbers.

function p(x,a)
    return { x = x, a = a}
end
a = 5
i = 3
x = 4
v = { }
    while x < 101 do
        r = math.mod(a,i)
        if r ~= 0 then
            if i == (a-1) then
                v[x] = p(x,a)
                print(v[x].x.." "..v[x].a)
                i = 3
                a = a + 2
                x = x + 1
            else
                i = i + 1
            end
        else
            i = 3
            a = a + 2
        end
    end

p = 4
while p < 101 do
        file = io.open("primo.txt","a+")
        file:write(v[p].x.." "..v[p].a.."\n")
        p = p + 1
end

voltar(back)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.