Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mathematics knundrum
Message
De
27/04/2003 11:35:25
 
 
À
26/04/2003 13:42:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00780672
Message ID:
00781967
Vues:
49
>>I think there's a large prize awaiting anyone who can prove a number prime without using brute force (perhaps more precisely, to create a formula which will unfailingly generate primes), which, I'm afraid, that algorithm is only capable of.
>>
>>So, maybe there's a practical benefit to theoretical math after all!
>>
>>
>> Jay
>
>hi Jay
>
>i am not that verse in Math, and i proppably missunderstood you, but is this what you're looking for (there is a website with primenumbers at http://www.utm.edu/research/primes/lists/small/1000.txt): -)
>CLEAR
>
>* *** main loop
>FOR i=1 TO 4060
>   IF IsPrime(i) = .T.
>      ?i
>   ENDIF
>ENDFOR
>
>RETURN

Gunnar --


   Yes, there are several algorithms to calculate primes. The one you present looks like it fits the bill.

   My reference to maintaining the database of prime numbers is that one could cycle through primes, rather than ALL numbers between 1 and INT (n/2) as this one does, and perhaps save a second or two<g>.

   Jay
>
>* *** *******************************************************
>FUNC IsPrime(Num2Check)
>   LOCAL ;
>      xi, ;
>      TargetLoop, ;
>      ReturnValue
>
>   ReturnValue = .T.
>   TargetLoop = ROUND(Num2Check/2, 0)
>   FOR xi=2 TO TargetLoop
>      IF MOD(Num2Check, xi) = 0
>         ReturnValue = .F.
>         EXIT
>      ENDIF
>   ENDFOR
>   RETURN(ReturnValue)
>ENDFUNC
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform