ChronoMath, une chronologie des MATHÉMATIQUES
à l'usage des professeurs de mathématiques, des étudiants et des élèves des lycées & collèges

Listing JavaScript : seconde conjecture de Polignac

<SCRIPT LANGUAGE=JavaScript>

var p,t

function polignac()
{
nmin=3;nmax=10000
nmin=prompt("Entrez n min :",nmin)
if (nmin==null) {return} else {nmin=eval(nmin);if(nmin%2==0) {nmin++}}
nmax=prompt("Entrez n max :",nmax)
if (nmax==null) {return} else {nmax=eval(nmax)}

co=0;
wdow=open("","","height=800,width=1024","scrollbars=1");
wdow.document.write("<PRE>")
compteur=0

for(n=nmin;n<=nmax;n=n+2)
{
p2=1;k=0;ok=0;
while(2*p2<n)
{
p2=2*p2;k++;p=n-p2;if(p==3){t=1} else {t=prem()}
if(t==1)
   {
   wdow.document.write(n+"=2^"+k+"+"+p+" |");p2=n;ok=1;co++
   if (co%8==0) {wdow.document.writeln("")}
   if (co%50000==0){co=0;if (!confirm("Je continue ?"))return}
   }
} // fin while

if(ok==0)
   {
   compteur=compteur+1
   wdow.document.writeln("")
   wdow.document.writeln("\n"+n+" ne vérifie pas la conjecture")
   wdow.document.writeln("")
   }
} // fin for

alert(compteur+" entiers entre "+nmin+" et "+nmax+"ne vérifient pas la conjecture")
} // fin polignac

function prem()               //  »  nombres premiers
{
d=1 ; a=0 ; rst = 1; rst2=1; t=0
if (p%3 != 0 && p%2 !=0)
   {
      while (d*d<=p && rst*rst2 >0)
        {
        a++
        d=6*a-1 ; rst = p % d
        d = d+2 ; rst2 = p % d
     }
     if(rst==0 || rst2==0) {t=0} else {t=1}
    }
return t
}

</SCRIPT>

JavaScript dans ChronoMath :  »


© Serge Mehl - www.chronomath.com