Jump to content
Sign in to follow this  
Dean

Conjectura de Goldbach

Recommended Posts

Dean    1
Dean

http://pt.wikipedia.org/wiki/Conjectura_de_Goldbach

 

Todo inteiro par maior que 2 pode ser escrito como a soma de 2 números primos.

 

No curso de iniciação científica que eu faço na Unicamp, a gente tava comentando sobre esse problema,até ganhamos um livro sobre ele.Então eu resolvi fazer um programinha que demonstra a validade da conjectura até um número natural n.

 

 

function crivo(t)
d = {} 
        function isPrimo(n)
                 if (n == 1) then
                   return false
                 end
                 if (n == 2) then
                   return true
                 end
                 f = math.floor(n/2)
                 for i = 2,f do
                     if n % i == 0 then
                       return false
                     end
                 end
        return true
        end
for i = 1,t do  
   if isPrimo(i) then
      table.insert(d,i)
   end
end
return d
end 

function goldbach(n)
if n < 4 then
  return print("N deve ser maior que 4!")
end
primos = crivo(n)
for i = 4,n,2 do
   for t,v in pairs(primos) do
   local y = inTable(primos,(i - v))
       if y then
          print(i.." = "..y.." + "..v)
          break
       end
   end
end
end

function inTable(t,v)
for x,y in pairs(t) do
   if y == v then
     return y
   end
end
 return false
end

goldbach(1000)

 

Pog powered

Edited by Mickfern

Share this post


Link to post
Share on other sites
nogareD    0
nogareD

for i = 4,n,2 do

 

i=4,n,2?

nao entendi

Share this post


Link to post
Share on other sites
Sinister    0
Sinister

i=4,n,2

 

i vai de 4 a n, 2 é o complemento

Share this post


Link to post
Share on other sites
Roku    0
Roku

gostei, aprendi bem com isso

legal fazer funções matematicas

script legal, vo da uma estudada

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×