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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle large Primes ( longer than 16 digits ) ?

Status
Not open for further replies.

pya

Technical User
Dec 18, 2020
40
AU
I have written a simple QBASI program that checks if a number is Prime.
But the program cannot handle numbers larger than 16 digits.
Is there a way I can use QBASI to check for Primes greater than 16 digits long?

My program below:

10 REM Prime Tester 7B
20 COLOR 15, 0, 0
30 DIM P AS _FLOAT
40 DIM N AS _FLOAT
60 INPUT "Number"; N
65 START = TIMER
70 IF N <= 0 GOTO 999
75 IF N = 1 THEN PRINT "Sorry! 1 is in the Unitary Group": GOTO 20
80 FOR P = 2 TO SQR(N)
90 IF N MOD P = 0 THEN PRINT "Composite": GOTO 130
100 NEXT P
110 COLOR 31, 0, 0
120 PRINT "Prime"
130 ELAPSED = TIMER - START
140 COLOR 15, 0, 0
150 PRINT "elapsed time is"; ELAPSED, "seconds"
160 BEEP
170 GOTO 20
999 END

Your help appreciated.

Regards

pya
 
Hi Mikrom,

Thanx for the reply.
Unfortunately, I am still learning QBASIC and had a hard time understanding all the code.
Is there any tutorial that will guide me through it.

Regards

pya
 
Hi Pya,
The idea of the link I mentioned, is to represent numbers as strings, but then you have to write your own functions like MOD() and SQRT() which you are using in your program, so that they work with large numerical strings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top