Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: A QBasic Program that calculates a range of prime numbers.

  1. #11
    tWebber
    Join Date
    Feb 2014
    Location
    Virgo Supercluster
    Faith
    Theistic, of sorts
    Gender
    Male
    Posts
    2,410
    Amen (Given)
    318
    Amen (Received)
    541
    I only understood about 5% of this thread.
    Learn to do right; seek justice. Defend the oppressed. Take up the cause of the fatherless; plead the case of the widow.--Isaiah 1:17

    I don't think that all forms o[f] slavery are inherently immoral.--seer

  2. #12
    tWebber 37818's Avatar
    Join Date
    Jan 2014
    Location
    So. California
    Faith
    Nontraditional Christian
    Gender
    Male
    Posts
    4,739
    Amen (Given)
    794
    Amen (Received)
    422
    Quote Originally Posted by fm93 View Post
    I only understood about 5% of this thread.
    OK.

    From what you did understand. Ask a question where this discussion went off from what you did understand. Where you are interested of course.
    . . . the Gospel of Christ, for it is [the] power of God to salvation to every [one] believing, . . . -- Romans 1:16.

    . . . that Christ died for our sins according to the scriptures; And that he was buried, and that he rose again the third day according to the scriptures: . . . -- 1 Corinthians 15:3, 4.

    Whosoever believeth that Jesus is the Christ is born of God: . . . -- 1 John 5:1.

  3. #13
    tWebber
    Join Date
    Feb 2014
    Location
    Virgo Supercluster
    Faith
    Theistic, of sorts
    Gender
    Male
    Posts
    2,410
    Amen (Given)
    318
    Amen (Received)
    541
    Quote Originally Posted by 37818 View Post
    OK.

    From what you did understand. Ask a question where this discussion went off from what you did understand. Where you are interested of course.
    No, no, I was just making a self-deprecating remark about my knowledge of computer science. Carry on.
    Learn to do right; seek justice. Defend the oppressed. Take up the cause of the fatherless; plead the case of the widow.--Isaiah 1:17

    I don't think that all forms o[f] slavery are inherently immoral.--seer

  4. #14
    tWebber 37818's Avatar
    Join Date
    Jan 2014
    Location
    So. California
    Faith
    Nontraditional Christian
    Gender
    Male
    Posts
    4,739
    Amen (Given)
    794
    Amen (Received)
    422
    Quote Originally Posted by fm93 View Post
    No, no, I was just making a self-deprecating remark about my knowledge of computer science. Carry on.
    Oh. I thought maybe you would like to discuss something regarding this. I know I left much unsaid.
    . . . the Gospel of Christ, for it is [the] power of God to salvation to every [one] believing, . . . -- Romans 1:16.

    . . . that Christ died for our sins according to the scriptures; And that he was buried, and that he rose again the third day according to the scriptures: . . . -- 1 Corinthians 15:3, 4.

    Whosoever believeth that Jesus is the Christ is born of God: . . . -- 1 John 5:1.

  5. #15
    tWebber 37818's Avatar
    Join Date
    Jan 2014
    Location
    So. California
    Faith
    Nontraditional Christian
    Gender
    Male
    Posts
    4,739
    Amen (Given)
    794
    Amen (Received)
    422
    Quote Originally Posted by 37818 View Post
    A test program for factoring Mersenne numbers. Where 2prime - 1 = to a value. This test version can only do up to 259 - 1 = 179951 * 3203431780337

    Code:
    INPUT p#
    IF p# = 2# OR p# = 3# THEN GOTO lbl
    IF (p# - 1#) / 6# <> INT((p# - 1#) / 6#) AND (p# + 1#) / 6# <> INT((p# + 1#) / 6#) THEN PRINT p#; "is not prime.": SYSTEM
    IF p# > 59# THEN PRINT "out of range.": SYSTEM
    
    lbl:
    x1# = -2#
    x2# = -1#
    x# = 0
    m# = 2# ^ p# - 1#
    c# = (m# - 1#) / (2# * p#)
    IF p# = 2# THEN GOTO lbla
    IF c# <> INT(c#) THEN PRINT p#; "is not prime.": SYSTEM
    IF (p# - 5) / 6 = INT((p# - 5) / 6) THEN GOTO lbla
    IF (p# - 7) / 6 = INT((p# - 7) / 6) THEN GOTO lblb
    
    
    lbla:
    x1# = x1# + 3#
    x# = x# + 3#
    y1# = (c# - x1#) / (2# * x1# * p# + 1#)
    IF x1# > y1# THEN GOTO lblz
    IF y1# = INT(y1#) THEN c# = y1#: GOSUB lblw: GOTO lbla
    y# = (c# - x#) / (2# * x# * p# + 1#)
    IF x# > y# THEN GOTO lblz
    IF y# = INT(y#) THEN c# = y#: GOSUB lbly: GOTO lbla
    IF y1# <> INT(y1#) AND y# <> INT(y#) THEN GOTO lbla
    GOTO lbla
    
    lblb:
    x2# = x2# + 3#
    x# = x# + 3#
    y2# = (c# - x2#) / (2# * x2# * p# + 1#)
    IF x2# > y2# THEN GOTO lblz
    IF y2# = INT(y2#) THEN c# = y2#: GOSUB lblx: GOTO lblb
    y# = (c# - x#) / (2# * x# * p# + 1#)
    IF x# > y# THEN GOTO lblz
    IF y# = INT(y#) THEN c# = y#: GOSUB lbly: GOTO lblb
    IF y2# <> INT(y2#) AND y# <> INT(y#) THEN GOTO lblb
    GOTO lblb
    
    lblz:
    PRINT (2# * c# * p# + 1#)
    SYSTEM
    lblw:
    PRINT (2# * x1# * p# + 1#)
    RETURN
    lblx:
    PRINT (2# * x2# * p# + 1#)
    RETURN
    lbly:
    PRINT (2# * x# * p# + 1#)
    RETURN
    Here is an improved edit:
    Code:
    INPUT p#
    IF p# = 2# OR p# = 3# THEN GOTO lbl
    IF (p# - 1#) / 6# <> INT((p# - 1#) / 6#) AND (p# + 1#) / 6# <> INT((p# + 1#) / 6#) THEN PRINT p#; "is not prime.": SYSTEM
    IF p# > 59# THEN PRINT "out of range.": SYSTEM
    
    lbl:
    x# = 0
    k# = 0
    m# = 2# ^ p# - 1#
    c# = (m# - 1#) / (p#)
    IF c# <> INT(c#) THEN PRINT p#; "is not prime.": SYSTEM
    IF p# = 2# THEN GOTO lbla
    IF p# MOD 6# = 5# THEN GOTO lbla
    IF p# MOD 6# = 1# THEN GOTO lblb
    
    lbla:
    IF k# = 2# THEN k# = 4# ELSE k# = 2#
    x# = x# + k#
    y# = (c# - x#) / (x# * p# + 1#)
    IF x# > y# THEN GOTO lblz
    IF y# <> INT(y#) THEN GOTO lbla
    IF y# = INT(y#) THEN c# = y#: GOSUB lbly: GOTO lbla
    GOTO lblz
    
    lblb:
    IF k# = 4# THEN k# = 2# ELSE k# = 4#
    x# = x# + k#
    y# = (c# - x#) / (x# * p# + 1#)
    IF x# > y# THEN GOTO lblz
    IF y# <> INT(y#) THEN GOTO lblb
    IF y# = INT(y#) THEN c# = y#: GOSUB lbly: GOTO lblb
    GOTO lblz
    
    
    lblz:
    PRINT (c# * p# + 1#)
    SYSTEM
    lbly:
    PRINT (x# * p# + 1#)
    RETURN
    Yes, further improvements can be made. Needs to be written in an assembly code with less limited number lengths.
    Last edited by 37818; 10-29-2017 at 05:39 PM.
    . . . the Gospel of Christ, for it is [the] power of God to salvation to every [one] believing, . . . -- Romans 1:16.

    . . . that Christ died for our sins according to the scriptures; And that he was buried, and that he rose again the third day according to the scriptures: . . . -- 1 Corinthians 15:3, 4.

    Whosoever believeth that Jesus is the Christ is born of God: . . . -- 1 John 5:1.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •