Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in Exponentiation

Status
Not open for further replies.

pya

Technical User
Dec 18, 2020
40
AU
Folks,

I am trying to generate Mill's Primes and the code is very simple.

For K = 1 and 2, the program gives the correct answers of 2 and 11.
But, for K = 3 it gives 1359 with the M value specified.
According to the maths (and Excel), the correct answer should be 1361 - the 3rd Mill's Prime.

I fail to understand where my calculation is going wrong.

Can someone please help.

Regards

pa99

10 CLS
20 REM Generate Mill’s Primes
30 REM Mill’s Constant = 1.3063778838630806904686144926...
40 DIM P AS DOUBLE
45 DIM M AS DOUBLE
50 INPUT “Number of Primes” ; K
60 M = 1.306337788
80 FOR N = 1 TO K
90 E = 3^N
100 P = M^E
120 PRINT FIX(P), M
130 NEXT N
999 END
 
If you use more precise constant
Code:
60 M = 1.3063778838630806904686144926
you will get for K = 3 the result P = 1361
 
Hi pya,

I learned something new from you again :)
As a former mathematician, I've never heard of Mill's prime numbers or those constants - almost unbelievable. I only read about it yesterday on Wikipedia: I studied math and taught in a college for about 6 years. But I was mostly into numerical mathematics, differential equations, optimization, and statistics. Number theory has never been an area of interest to me.
 
Hi mikrom,

A kindred spirit.

Studied maths at uni but never enjoyed it.
Too many exams and too much pressure.

Now I enjoy it thoroughly (along with Physics).
My main interests are in Prime Numbers and Cantor's Infinite Set theory.
I also enjoy Linear Programming and use Excel's Solver to keep in touch.

Regards

pya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top