Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Primes and patterns into 19-digit integers
#1
This is a program I created when very bored to take a list of 19-digit integers from a text file and figure out if they're prime or not. I was trying to get a palindrome out of one of them but failed so far LOL.

The program is listed below but is worthless without the data files which are part of the attachment.

Code: (Select All)
'by mnrvovrfc, first revision Dec-2020
$CHECKING:OFF
_DEFINE A-Z AS LONG
DIM PRIMEBIT(1 TO 4999995) AS _BIT
DIM PVAL(1 TO 1000) AS _UNSIGNED _INTEGER64
DIM X AS _UNSIGNED _INTEGER64, PLIMIT AS _UNSIGNED LONG, Y AS _UNSIGNED LONG, Z AS _UNSIGNED LONG
DIM fl AS _BIT, ofl AS _BIT, q AS _BYTE

dataf$ = makeuserprof$("%DOCU%/prime19dig-pref.txt")
ifile$ = makeuserprof$("%DOCU%/prime19dig.txt")
outf$ = makeuserprof$("%DOCU%/prime19dig-out.txt")

IF NOT _FILEEXISTS(ifile$) THEN
    PRINT "Cannot run without this file: prime20dig.txt"
    END
END IF

IF _FILEEXISTS(dataf$) THEN
    fi = FREEFILE
    OPEN dataf$ FOR INPUT AS fi
    LINE INPUT #fi, a$
    CLOSE fi
    sop = VAL(LTRIM$(a$))
    IF sop < 1 THEN sop = 1
ELSE
    sop = 1
END IF

PRINT "Please wait, loading ..."
READ Y
READ Y
DO WHILE Y
    Y = (Y - 1) \ 2
    PRIMEBIT(Y) = -1
    READ Y
LOOP
PRINT "Checking input file..."
GOSUB setmytitle
fl = -1
l = 1
u = 1
v = UBOUND(PVAL)
fi = FREEFILE
OPEN ifile$ FOR INPUT AS fi
SEEK #fi, sop
DO UNTIL EOF(fi)
    LINE INPUT #fi, a$
    IF a$ <> "" THEN
        PVAL(u) = VAL(a$)
        u = u + 1
        IF fl THEN fl = 0
        IF u > v THEN sop = SEEK(fi): EXIT DO
    END IF
    l = l + 1
LOOP
IF EOF(fi) THEN sop = 1
CLOSE fi
IF fl THEN
    PRINT "Nothing to do!"
    END
END IF

COLOR 15, 5: CLS
GOSUB setmytitle
_DISPLAY
ofl = 0
FOR u = 1 TO v
    X = PVAL(u)
    IF X = 0 THEN EXIT FOR
    IF u MOD 10 = 0 THEN q = _EXIT
    IF q THEN EXIT FOR
    omb = _MOUSEINPUT
    IF omb THEN
        IF _MOUSEBUTTON(1) THEN ofl = -1
        IF _MOUSEBUTTON(2) THEN ofl = -1
    END IF
    IF ofl THEN
        ofl = 0
        _DISPLAY
    END IF
    fl = -1
    Z = 1
    FOR Y = 1 TO 4999995
        Z = Z + 2
        IF PRIMEBIT(Y) THEN
            IF X MOD Z = 0 THEN fl = 0: EXIT FOR
        END IF
    NEXT
    IF fl THEN
        PLIMIT = FIX(SQR(X * 1.0#))
        FOR Y = 9999993 TO PLIMIT STEP 2
            IF X MOD Y = 0 THEN fl = 0: EXIT FOR
        NEXT
    END IF
    IF fl THEN
        PRINT X
        GOSUB setmytitle
        _DISPLAY
    ELSE
        PVAL(u) = 0
    END IF
NEXT

IF q = 0 THEN
    fo = FREEFILE
    IF _FILEEXISTS(outf$) THEN
        OPEN outf$ FOR APPEND AS fo
    ELSE
        OPEN outf$ FOR OUTPUT AS fo
    END IF
    FOR u = 1 TO v
        IF PVAL(u) > 0 THEN
            PRINT #fo, STR$(PVAL(u))
        END IF
    NEXT
    CLOSE fo
    fo = FREEFILE
    OPEN dataf$ FOR OUTPUT AS fo
    PRINT #fo, sop
    CLOSE fo
    COLOR 14
    PRINT "Completed!"
    _DISPLAY
    _DELAY 3
END IF
SYSTEM

setmytitle:
_TITLE "Prime 20 Digits"
RETURN


FUNCTION makeuserprof$ (s$)
    IF s$ = "" THEN
        makeuserprof$ = ""
        EXIT FUNCTION
    END IF
    mypath$ = s$

    ''added NA27
    IF LEFT$(mypath$, 2) = ".\" OR LEFT$(mypath$, 2) = "./" THEN
        afile$ = "qb64curdir.txt"
        b$ = "%USERPROFILE%"
        IF _FILEEXISTS(afile$) THEN
            c$ = ""
            fi = FREEFILE
            OPEN afile$ FOR INPUT AS fi
            IF NOT EOF(fi) THEN
                LINE INPUT #fi, c$
                c$ = RTRIM$(LTRIM$(c$))
            END IF
            CLOSE fi
            IF c$ <> "" THEN
                IF RIGHT$(c$, 1) = "\" OR RIGHT$(c$, 1) = "/" THEN
                    b$ = LEFT$(c$, LEN(c$) - 1)
                ELSE
                    b$ = c$
                END IF
                mypath$ = b$ + MID$(mypath$, 2)
            END IF
        END IF
    END IF

    u = INSTR(mypath$, "/")
    v = INSTR(mypath$, "\")
    IF u = 0 AND v = 0 THEN
        makeuserprof$ = ""
        EXIT FUNCTION
    END IF
    IF u > 0 THEN
        ReplaceString2 mypath$, "/", "\", 0
    END IF
    u = INSTR(mypath$, "%")
    IF u > 0 THEN
        v = INSTR(u + 1, mypath$, "%\")
    ELSE
        u = 0
    END IF
    IF u = 1 AND v > u THEN
        ''continue function code
    ELSE
        makeuserprof$ = mypath$
        EXIT FUNCTION
    END IF
    a$ = UCASE$(mypath$)
    uprof$ = ENVIRON$("USERPROFILE")
    FOR i = 1 TO 6
        SELECT CASE i
            CASE 1
                b$ = "%USERPROFILE%"
                c$ = uprof$
            CASE 2
                b$ = "%USERPROF%"
                ''c$ same as case 1
            CASE 3
                b$ = "%MUSIC%"
                c$ = uprof$ + "\Music"
            CASE 4
                b$ = "%DOCS%"
                c$ = uprof$ + "\Documents"
            CASE 5
                b$ = "%DOCU%"
                c$ = uprof$ + "\Documents"
            CASE 6
                b$ = "%PIC%"
                c$ = uprof$ + "\Pictures"
        END SELECT
        IF INSTR(a$, b$) THEN
            ReplaceString2 mypath$, b$, c$, 1
            EXIT FOR
        END IF
    NEXT
    makeuserprof$ = mypath$
END FUNCTION

FUNCTION returntfn$ (femplate$)
    STATIC sernum AS LONG, sernumset AS _BIT
    sret$ = ""
    a$ = LTRIM$(RTRIM$(femplate$))
    IF a$ <> "" THEN
        u = INSTR(a$, "|")
        IF u > 0 THEN
            IF LEFT$(a$, 1) = "%" OR INSTR(a$, "/") > 0 THEN
                a$ = makeuserprof$(a$)
            END IF
            IF sernumset = 0 THEN
                sernumset = NOT sernumset
                sernum = 1
            END IF
            IF RIGHT$(a$, 1) <> "\" THEN
                DO
                    n$ = LTRIM$(STR$(sernum))
                    IF LEN(n$) < 4 THEN n$ = LEFT$("0000", 4 - LEN(n$))
                    sret$ = a$
                    ReplaceString2 sret$, "|", n$, 1
                    sernum = sernum + 1
                LOOP UNTIL NOT _FILEEXISTS(sret$)
            END IF
        END IF
    END IF
    returntfn$ = sret$
END FUNCTION

SUB ReplaceString2 (tx AS STRING, sfind AS STRING, repl AS STRING, numtimes AS _UNSIGNED LONG)
    DIM s AS STRING, t AS STRING
    DIM ls AS _UNSIGNED LONG, lx AS _UNSIGNED LONG, count AS _UNSIGNED LONG, j AS _UNSIGNED LONG
    IF (tx = "") OR (sfind = "") OR (sfind = repl) OR (LEN(sfind) > LEN(tx)) THEN EXIT SUB
    s = UCASE$(sfind): t = UCASE$(tx)
    ls = LEN(s)
    count = 0
    goahead = 1
    DO
        u = INSTR(t, s)
        IF u > 0 THEN
            tx$ = LEFT$(tx, u - 1) + repl + MID$(tx, u + ls)
            t = UCASE$(tx)
            IF numtimes > 0 THEN count = count + 1: IF count >= numtimes THEN goahead = 0
        ELSE
            goahead = 0
        END IF
    LOOP WHILE goahead
END SUB

'$INCLUDE: 'tprime.bi'

As the program is presented, it looks for a file named "prime19dig.txt" in the user's Documents directory. This file is over 80MB in size! Do not try to open it in Notepad or any other text editor that cannot handle files larger than 1MB. I created it and a few others with a Lua script, being more interested in patterns of the digits. It's because trying to go sequentially would be very slow and come up with numbers boring to look at or could peel the paint from the walls. Such as 10000000002835706257.

This program only takes numbers from a list and figures out if they're prime or not. If prime they are listed on the screen and they are also sent to an output file called "prime19dig-out.txt". The program should end in 5 to 10 minutes on a dual-core CPU laptop created within the last five years. Then the user could choose to run it again to pick up where it left off. This could be done for a while until it runs out of "candidates" and it starts from the beginning -- then you say give me another 80MB file. This information is saved in a file called "prime19dig-pref.txt", should not be tampered by anybody who hasn't read and understood the source code!

I have indeed created another version of this program that focused only on numbers higher than 18 followed by 18 zeros. But the program posted here is only one example of what could be done with 64-bit integers. Imagine when 128-bit becomes the norm later on...

Note: there was another number 10043560040404043561 that figured in one of my fantasy stories, about a rock band that created a song singing it out. It was supposed to be for LOL's. Imagine like Katy Perry or Springsteen singing, "zero zero four, zero four, zero four, zero four, three five six!" Sorry not a good judge with female solo artists after Madonna and others ruined my sense for pop-rock forever. But that integer is not prime, must add six to it. Wink

(Maybe I should use an external file-sharing service because I made one attempt to upload but it didn't display in the available list of attachments, although it reflected the large jump in size of total attachments. I will have to delete one of the two attempts later, if it could be found.)


.zip   prime19dig-by-mnrvovrfc.zip (Size: 8.64 MB / Downloads: 48)
Reply
#2
761 prime palindromes > 1000 up to 100,000,000
Code: (Select All)
' 2310 wheel sieve.bas for QB64 fork (B+=MGA) 2017-08-18 copy and trans to QB64
'from: First Factors v5.bas 11/29/14 1am using program to write wheel 2310 step size

'QB64 results
'topN = 1000000, primes 78,4987, .18 secs, 8169 twins last 999959,  999961
'topN = 10000000, primes 664,579, 1.98 secs, 58,980 twins last 9999971,  9999973
'topN = 100000000, primes 5,761,455, 21.57 secs, 440,312 twins last 99999587,  99999589
' out of memory for 1 billion

_Define A-Z As _INTEGER64
Option Base 1
Common Shared ff(), topN
topN = 1223 'first 200 primes test
topN = 100000000
testlimitN = Sqr(topN)
Dim ff(topN + 2310)
tStart# = Timer(.001)

For i = 0 To topN Step 2310
    ff(i + 2) = 2: ff(i + 3) = 3: ff(i + 4) = 2: ff(i + 5) = 5: ff(i + 6) = 2: ff(i + 7) = 7: ff(i + 8) = 2: ff(i + 9) = 3: ff(i + 10) = 2: ff(i + 11) = 11
    ff(i + 12) = 2: ff(i + 14) = 2: ff(i + 15) = 3: ff(i + 16) = 2: ff(i + 18) = 2: ff(i + 20) = 2: ff(i + 21) = 3: ff(i + 22) = 2: ff(i + 24) = 2: ff(i + 25) = 5
    ff(i + 26) = 2: ff(i + 27) = 3: ff(i + 28) = 2: ff(i + 30) = 2: ff(i + 32) = 2: ff(i + 33) = 3: ff(i + 34) = 2: ff(i + 35) = 5: ff(i + 36) = 2: ff(i + 38) = 2
    ff(i + 39) = 3: ff(i + 40) = 2: ff(i + 42) = 2: ff(i + 44) = 2: ff(i + 45) = 3: ff(i + 46) = 2: ff(i + 48) = 2: ff(i + 49) = 7: ff(i + 50) = 2: ff(i + 51) = 3
    ff(i + 52) = 2: ff(i + 54) = 2: ff(i + 55) = 5: ff(i + 56) = 2: ff(i + 57) = 3: ff(i + 58) = 2: ff(i + 60) = 2: ff(i + 62) = 2: ff(i + 63) = 3: ff(i + 64) = 2
    ff(i + 65) = 5: ff(i + 66) = 2: ff(i + 68) = 2: ff(i + 69) = 3: ff(i + 70) = 2: ff(i + 72) = 2: ff(i + 74) = 2: ff(i + 75) = 3: ff(i + 76) = 2: ff(i + 77) = 7
    ff(i + 78) = 2: ff(i + 80) = 2: ff(i + 81) = 3: ff(i + 82) = 2: ff(i + 84) = 2: ff(i + 85) = 5: ff(i + 86) = 2: ff(i + 87) = 3: ff(i + 88) = 2: ff(i + 90) = 2
    ff(i + 91) = 7: ff(i + 92) = 2: ff(i + 93) = 3: ff(i + 94) = 2: ff(i + 95) = 5: ff(i + 96) = 2: ff(i + 98) = 2: ff(i + 99) = 3: ff(i + 100) = 2: ff(i + 102) = 2
    ff(i + 104) = 2: ff(i + 105) = 3: ff(i + 106) = 2: ff(i + 108) = 2: ff(i + 110) = 2: ff(i + 111) = 3: ff(i + 112) = 2: ff(i + 114) = 2: ff(i + 115) = 5: ff(i + 116) = 2
    ff(i + 117) = 3: ff(i + 118) = 2: ff(i + 119) = 7: ff(i + 120) = 2: ff(i + 121) = 11: ff(i + 122) = 2: ff(i + 123) = 3: ff(i + 124) = 2: ff(i + 125) = 5: ff(i + 126) = 2
    ff(i + 128) = 2: ff(i + 129) = 3: ff(i + 130) = 2: ff(i + 132) = 2: ff(i + 133) = 7: ff(i + 134) = 2: ff(i + 135) = 3: ff(i + 136) = 2: ff(i + 138) = 2: ff(i + 140) = 2
    ff(i + 141) = 3: ff(i + 142) = 2: ff(i + 143) = 11: ff(i + 144) = 2: ff(i + 145) = 5: ff(i + 146) = 2: ff(i + 147) = 3: ff(i + 148) = 2: ff(i + 150) = 2: ff(i + 152) = 2
    ff(i + 153) = 3: ff(i + 154) = 2: ff(i + 155) = 5: ff(i + 156) = 2: ff(i + 158) = 2: ff(i + 159) = 3: ff(i + 160) = 2: ff(i + 161) = 7: ff(i + 162) = 2: ff(i + 164) = 2
    ff(i + 165) = 3: ff(i + 166) = 2: ff(i + 168) = 2: ff(i + 170) = 2: ff(i + 171) = 3: ff(i + 172) = 2: ff(i + 174) = 2: ff(i + 175) = 5: ff(i + 176) = 2: ff(i + 177) = 3
    ff(i + 178) = 2: ff(i + 180) = 2: ff(i + 182) = 2: ff(i + 183) = 3: ff(i + 184) = 2: ff(i + 185) = 5: ff(i + 186) = 2: ff(i + 187) = 11: ff(i + 188) = 2: ff(i + 189) = 3
    ff(i + 190) = 2: ff(i + 192) = 2: ff(i + 194) = 2: ff(i + 195) = 3: ff(i + 196) = 2: ff(i + 198) = 2: ff(i + 200) = 2: ff(i + 201) = 3: ff(i + 202) = 2: ff(i + 203) = 7
    ff(i + 204) = 2: ff(i + 205) = 5: ff(i + 206) = 2: ff(i + 207) = 3: ff(i + 208) = 2: ff(i + 209) = 11: ff(i + 210) = 2: ff(i + 212) = 2: ff(i + 213) = 3: ff(i + 214) = 2
    ff(i + 215) = 5: ff(i + 216) = 2: ff(i + 217) = 7: ff(i + 218) = 2: ff(i + 219) = 3: ff(i + 220) = 2: ff(i + 222) = 2: ff(i + 224) = 2: ff(i + 225) = 3: ff(i + 226) = 2
    ff(i + 228) = 2: ff(i + 230) = 2: ff(i + 231) = 3: ff(i + 232) = 2: ff(i + 234) = 2: ff(i + 235) = 5: ff(i + 236) = 2: ff(i + 237) = 3: ff(i + 238) = 2: ff(i + 240) = 2
    ff(i + 242) = 2: ff(i + 243) = 3: ff(i + 244) = 2: ff(i + 245) = 5: ff(i + 246) = 2: ff(i + 248) = 2: ff(i + 249) = 3: ff(i + 250) = 2: ff(i + 252) = 2: ff(i + 253) = 11
    ff(i + 254) = 2: ff(i + 255) = 3: ff(i + 256) = 2: ff(i + 258) = 2: ff(i + 259) = 7: ff(i + 260) = 2: ff(i + 261) = 3: ff(i + 262) = 2: ff(i + 264) = 2: ff(i + 265) = 5
    ff(i + 266) = 2: ff(i + 267) = 3: ff(i + 268) = 2: ff(i + 270) = 2: ff(i + 272) = 2: ff(i + 273) = 3: ff(i + 274) = 2: ff(i + 275) = 5: ff(i + 276) = 2: ff(i + 278) = 2
    ff(i + 279) = 3: ff(i + 280) = 2: ff(i + 282) = 2: ff(i + 284) = 2: ff(i + 285) = 3: ff(i + 286) = 2: ff(i + 287) = 7: ff(i + 288) = 2: ff(i + 290) = 2: ff(i + 291) = 3
    ff(i + 292) = 2: ff(i + 294) = 2: ff(i + 295) = 5: ff(i + 296) = 2: ff(i + 297) = 3: ff(i + 298) = 2: ff(i + 300) = 2: ff(i + 301) = 7: ff(i + 302) = 2: ff(i + 303) = 3
    ff(i + 304) = 2: ff(i + 305) = 5: ff(i + 306) = 2: ff(i + 308) = 2: ff(i + 309) = 3: ff(i + 310) = 2: ff(i + 312) = 2: ff(i + 314) = 2: ff(i + 315) = 3: ff(i + 316) = 2
    ff(i + 318) = 2: ff(i + 319) = 11: ff(i + 320) = 2: ff(i + 321) = 3: ff(i + 322) = 2: ff(i + 324) = 2: ff(i + 325) = 5: ff(i + 326) = 2: ff(i + 327) = 3: ff(i + 328) = 2
    ff(i + 329) = 7: ff(i + 330) = 2: ff(i + 332) = 2: ff(i + 333) = 3: ff(i + 334) = 2: ff(i + 335) = 5: ff(i + 336) = 2: ff(i + 338) = 2: ff(i + 339) = 3: ff(i + 340) = 2
    ff(i + 341) = 11: ff(i + 342) = 2: ff(i + 343) = 7: ff(i + 344) = 2: ff(i + 345) = 3: ff(i + 346) = 2: ff(i + 348) = 2: ff(i + 350) = 2: ff(i + 351) = 3: ff(i + 352) = 2
    ff(i + 354) = 2: ff(i + 355) = 5: ff(i + 356) = 2: ff(i + 357) = 3: ff(i + 358) = 2: ff(i + 360) = 2: ff(i + 362) = 2: ff(i + 363) = 3: ff(i + 364) = 2: ff(i + 365) = 5
    ff(i + 366) = 2: ff(i + 368) = 2: ff(i + 369) = 3: ff(i + 370) = 2: ff(i + 371) = 7: ff(i + 372) = 2: ff(i + 374) = 2: ff(i + 375) = 3: ff(i + 376) = 2: ff(i + 378) = 2
    ff(i + 380) = 2: ff(i + 381) = 3: ff(i + 382) = 2: ff(i + 384) = 2: ff(i + 385) = 5: ff(i + 386) = 2: ff(i + 387) = 3: ff(i + 388) = 2: ff(i + 390) = 2: ff(i + 392) = 2
    ff(i + 393) = 3: ff(i + 394) = 2: ff(i + 395) = 5: ff(i + 396) = 2: ff(i + 398) = 2: ff(i + 399) = 3: ff(i + 400) = 2: ff(i + 402) = 2: ff(i + 404) = 2: ff(i + 405) = 3
    ff(i + 406) = 2: ff(i + 407) = 11: ff(i + 408) = 2: ff(i + 410) = 2: ff(i + 411) = 3: ff(i + 412) = 2: ff(i + 413) = 7: ff(i + 414) = 2: ff(i + 415) = 5: ff(i + 416) = 2
    ff(i + 417) = 3: ff(i + 418) = 2: ff(i + 420) = 2: ff(i + 422) = 2: ff(i + 423) = 3: ff(i + 424) = 2: ff(i + 425) = 5: ff(i + 426) = 2: ff(i + 427) = 7: ff(i + 428) = 2
    ff(i + 429) = 3: ff(i + 430) = 2: ff(i + 432) = 2: ff(i + 434) = 2: ff(i + 435) = 3: ff(i + 436) = 2: ff(i + 438) = 2: ff(i + 440) = 2: ff(i + 441) = 3: ff(i + 442) = 2
    ff(i + 444) = 2: ff(i + 445) = 5: ff(i + 446) = 2: ff(i + 447) = 3: ff(i + 448) = 2: ff(i + 450) = 2: ff(i + 451) = 11: ff(i + 452) = 2: ff(i + 453) = 3: ff(i + 454) = 2
    ff(i + 455) = 5: ff(i + 456) = 2: ff(i + 458) = 2: ff(i + 459) = 3: ff(i + 460) = 2: ff(i + 462) = 2: ff(i + 464) = 2: ff(i + 465) = 3: ff(i + 466) = 2: ff(i + 468) = 2
    ff(i + 469) = 7: ff(i + 470) = 2: ff(i + 471) = 3: ff(i + 472) = 2: ff(i + 473) = 11: ff(i + 474) = 2: ff(i + 475) = 5: ff(i + 476) = 2: ff(i + 477) = 3: ff(i + 478) = 2
    ff(i + 480) = 2: ff(i + 482) = 2: ff(i + 483) = 3: ff(i + 484) = 2: ff(i + 485) = 5: ff(i + 486) = 2: ff(i + 488) = 2: ff(i + 489) = 3: ff(i + 490) = 2: ff(i + 492) = 2
    ff(i + 494) = 2: ff(i + 495) = 3: ff(i + 496) = 2: ff(i + 497) = 7: ff(i + 498) = 2: ff(i + 500) = 2: ff(i + 501) = 3: ff(i + 502) = 2: ff(i + 504) = 2: ff(i + 505) = 5
    ff(i + 506) = 2: ff(i + 507) = 3: ff(i + 508) = 2: ff(i + 510) = 2: ff(i + 511) = 7: ff(i + 512) = 2: ff(i + 513) = 3: ff(i + 514) = 2: ff(i + 515) = 5: ff(i + 516) = 2
    ff(i + 517) = 11: ff(i + 518) = 2: ff(i + 519) = 3: ff(i + 520) = 2: ff(i + 522) = 2: ff(i + 524) = 2: ff(i + 525) = 3: ff(i + 526) = 2: ff(i + 528) = 2: ff(i + 530) = 2
    ff(i + 531) = 3: ff(i + 532) = 2: ff(i + 534) = 2: ff(i + 535) = 5: ff(i + 536) = 2: ff(i + 537) = 3: ff(i + 538) = 2: ff(i + 539) = 7: ff(i + 540) = 2: ff(i + 542) = 2
    ff(i + 543) = 3: ff(i + 544) = 2: ff(i + 545) = 5: ff(i + 546) = 2: ff(i + 548) = 2: ff(i + 549) = 3: ff(i + 550) = 2: ff(i + 552) = 2: ff(i + 553) = 7: ff(i + 554) = 2
    ff(i + 555) = 3: ff(i + 556) = 2: ff(i + 558) = 2: ff(i + 560) = 2: ff(i + 561) = 3: ff(i + 562) = 2: ff(i + 564) = 2: ff(i + 565) = 5: ff(i + 566) = 2: ff(i + 567) = 3
    ff(i + 568) = 2: ff(i + 570) = 2: ff(i + 572) = 2: ff(i + 573) = 3: ff(i + 574) = 2: ff(i + 575) = 5: ff(i + 576) = 2: ff(i + 578) = 2: ff(i + 579) = 3: ff(i + 580) = 2
    ff(i + 581) = 7: ff(i + 582) = 2: ff(i + 583) = 11: ff(i + 584) = 2: ff(i + 585) = 3: ff(i + 586) = 2: ff(i + 588) = 2: ff(i + 590) = 2: ff(i + 591) = 3: ff(i + 592) = 2
    ff(i + 594) = 2: ff(i + 595) = 5: ff(i + 596) = 2: ff(i + 597) = 3: ff(i + 598) = 2: ff(i + 600) = 2: ff(i + 602) = 2: ff(i + 603) = 3: ff(i + 604) = 2: ff(i + 605) = 5
    ff(i + 606) = 2: ff(i + 608) = 2: ff(i + 609) = 3: ff(i + 610) = 2: ff(i + 612) = 2: ff(i + 614) = 2: ff(i + 615) = 3: ff(i + 616) = 2: ff(i + 618) = 2: ff(i + 620) = 2
    ff(i + 621) = 3: ff(i + 622) = 2: ff(i + 623) = 7: ff(i + 624) = 2: ff(i + 625) = 5: ff(i + 626) = 2: ff(i + 627) = 3: ff(i + 628) = 2: ff(i + 630) = 2: ff(i + 632) = 2
    ff(i + 633) = 3: ff(i + 634) = 2: ff(i + 635) = 5: ff(i + 636) = 2: ff(i + 637) = 7: ff(i + 638) = 2: ff(i + 639) = 3: ff(i + 640) = 2: ff(i + 642) = 2: ff(i + 644) = 2
    ff(i + 645) = 3: ff(i + 646) = 2: ff(i + 648) = 2: ff(i + 649) = 11: ff(i + 650) = 2: ff(i + 651) = 3: ff(i + 652) = 2: ff(i + 654) = 2: ff(i + 655) = 5: ff(i + 656) = 2
    ff(i + 657) = 3: ff(i + 658) = 2: ff(i + 660) = 2: ff(i + 662) = 2: ff(i + 663) = 3: ff(i + 664) = 2: ff(i + 665) = 5: ff(i + 666) = 2: ff(i + 668) = 2: ff(i + 669) = 3
    ff(i + 670) = 2: ff(i + 671) = 11: ff(i + 672) = 2: ff(i + 674) = 2: ff(i + 675) = 3: ff(i + 676) = 2: ff(i + 678) = 2: ff(i + 679) = 7: ff(i + 680) = 2: ff(i + 681) = 3
    ff(i + 682) = 2: ff(i + 684) = 2: ff(i + 685) = 5: ff(i + 686) = 2: ff(i + 687) = 3: ff(i + 688) = 2: ff(i + 690) = 2: ff(i + 692) = 2: ff(i + 693) = 3: ff(i + 694) = 2
    ff(i + 695) = 5: ff(i + 696) = 2: ff(i + 698) = 2: ff(i + 699) = 3: ff(i + 700) = 2: ff(i + 702) = 2: ff(i + 704) = 2: ff(i + 705) = 3: ff(i + 706) = 2: ff(i + 707) = 7
    ff(i + 708) = 2: ff(i + 710) = 2: ff(i + 711) = 3: ff(i + 712) = 2: ff(i + 714) = 2: ff(i + 715) = 5: ff(i + 716) = 2: ff(i + 717) = 3: ff(i + 718) = 2: ff(i + 720) = 2
    ff(i + 721) = 7: ff(i + 722) = 2: ff(i + 723) = 3: ff(i + 724) = 2: ff(i + 725) = 5: ff(i + 726) = 2: ff(i + 728) = 2: ff(i + 729) = 3: ff(i + 730) = 2: ff(i + 732) = 2
    ff(i + 734) = 2: ff(i + 735) = 3: ff(i + 736) = 2: ff(i + 737) = 11: ff(i + 738) = 2: ff(i + 740) = 2: ff(i + 741) = 3: ff(i + 742) = 2: ff(i + 744) = 2: ff(i + 745) = 5
    ff(i + 746) = 2: ff(i + 747) = 3: ff(i + 748) = 2: ff(i + 749) = 7: ff(i + 750) = 2: ff(i + 752) = 2: ff(i + 753) = 3: ff(i + 754) = 2: ff(i + 755) = 5: ff(i + 756) = 2
    ff(i + 758) = 2: ff(i + 759) = 3: ff(i + 760) = 2: ff(i + 762) = 2: ff(i + 763) = 7: ff(i + 764) = 2: ff(i + 765) = 3: ff(i + 766) = 2: ff(i + 768) = 2: ff(i + 770) = 2
    ff(i + 771) = 3: ff(i + 772) = 2: ff(i + 774) = 2: ff(i + 775) = 5: ff(i + 776) = 2: ff(i + 777) = 3: ff(i + 778) = 2: ff(i + 780) = 2: ff(i + 781) = 11: ff(i + 782) = 2
    ff(i + 783) = 3: ff(i + 784) = 2: ff(i + 785) = 5: ff(i + 786) = 2: ff(i + 788) = 2: ff(i + 789) = 3: ff(i + 790) = 2: ff(i + 791) = 7: ff(i + 792) = 2: ff(i + 794) = 2
    ff(i + 795) = 3: ff(i + 796) = 2: ff(i + 798) = 2: ff(i + 800) = 2: ff(i + 801) = 3: ff(i + 802) = 2: ff(i + 803) = 11: ff(i + 804) = 2: ff(i + 805) = 5: ff(i + 806) = 2
    ff(i + 807) = 3: ff(i + 808) = 2: ff(i + 810) = 2: ff(i + 812) = 2: ff(i + 813) = 3: ff(i + 814) = 2: ff(i + 815) = 5: ff(i + 816) = 2: ff(i + 818) = 2: ff(i + 819) = 3
    ff(i + 820) = 2: ff(i + 822) = 2: ff(i + 824) = 2: ff(i + 825) = 3: ff(i + 826) = 2: ff(i + 828) = 2: ff(i + 830) = 2: ff(i + 831) = 3: ff(i + 832) = 2: ff(i + 833) = 7
    ff(i + 834) = 2: ff(i + 835) = 5: ff(i + 836) = 2: ff(i + 837) = 3: ff(i + 838) = 2: ff(i + 840) = 2: ff(i + 842) = 2: ff(i + 843) = 3: ff(i + 844) = 2: ff(i + 845) = 5
    ff(i + 846) = 2: ff(i + 847) = 7: ff(i + 848) = 2: ff(i + 849) = 3: ff(i + 850) = 2: ff(i + 852) = 2: ff(i + 854) = 2: ff(i + 855) = 3: ff(i + 856) = 2: ff(i + 858) = 2
    ff(i + 860) = 2: ff(i + 861) = 3: ff(i + 862) = 2: ff(i + 864) = 2: ff(i + 865) = 5: ff(i + 866) = 2: ff(i + 867) = 3: ff(i + 868) = 2: ff(i + 869) = 11: ff(i + 870) = 2
    ff(i + 872) = 2: ff(i + 873) = 3: ff(i + 874) = 2: ff(i + 875) = 5: ff(i + 876) = 2: ff(i + 878) = 2: ff(i + 879) = 3: ff(i + 880) = 2: ff(i + 882) = 2: ff(i + 884) = 2
    ff(i + 885) = 3: ff(i + 886) = 2: ff(i + 888) = 2: ff(i + 889) = 7: ff(i + 890) = 2: ff(i + 891) = 3: ff(i + 892) = 2: ff(i + 894) = 2: ff(i + 895) = 5: ff(i + 896) = 2
    ff(i + 897) = 3: ff(i + 898) = 2: ff(i + 900) = 2: ff(i + 902) = 2: ff(i + 903) = 3: ff(i + 904) = 2: ff(i + 905) = 5: ff(i + 906) = 2: ff(i + 908) = 2: ff(i + 909) = 3
    ff(i + 910) = 2: ff(i + 912) = 2: ff(i + 913) = 11: ff(i + 914) = 2: ff(i + 915) = 3: ff(i + 916) = 2: ff(i + 917) = 7: ff(i + 918) = 2: ff(i + 920) = 2: ff(i + 921) = 3
    ff(i + 922) = 2: ff(i + 924) = 2: ff(i + 925) = 5: ff(i + 926) = 2: ff(i + 927) = 3: ff(i + 928) = 2: ff(i + 930) = 2: ff(i + 931) = 7: ff(i + 932) = 2: ff(i + 933) = 3
    ff(i + 934) = 2: ff(i + 935) = 5: ff(i + 936) = 2: ff(i + 938) = 2: ff(i + 939) = 3: ff(i + 940) = 2: ff(i + 942) = 2: ff(i + 944) = 2: ff(i + 945) = 3: ff(i + 946) = 2
    ff(i + 948) = 2: ff(i + 950) = 2: ff(i + 951) = 3: ff(i + 952) = 2: ff(i + 954) = 2: ff(i + 955) = 5: ff(i + 956) = 2: ff(i + 957) = 3: ff(i + 958) = 2: ff(i + 959) = 7
    ff(i + 960) = 2: ff(i + 962) = 2: ff(i + 963) = 3: ff(i + 964) = 2: ff(i + 965) = 5: ff(i + 966) = 2: ff(i + 968) = 2: ff(i + 969) = 3: ff(i + 970) = 2: ff(i + 972) = 2
    ff(i + 973) = 7: ff(i + 974) = 2: ff(i + 975) = 3: ff(i + 976) = 2: ff(i + 978) = 2: ff(i + 979) = 11: ff(i + 980) = 2: ff(i + 981) = 3: ff(i + 982) = 2: ff(i + 984) = 2
    ff(i + 985) = 5: ff(i + 986) = 2: ff(i + 987) = 3: ff(i + 988) = 2: ff(i + 990) = 2: ff(i + 992) = 2: ff(i + 993) = 3: ff(i + 994) = 2: ff(i + 995) = 5: ff(i + 996) = 2
    ff(i + 998) = 2: ff(i + 999) = 3: ff(i + 1000) = 2: ff(i + 1001) = 7: ff(i + 1002) = 2: ff(i + 1004) = 2: ff(i + 1005) = 3: ff(i + 1006) = 2: ff(i + 1008) = 2: ff(i + 1010) = 2
    ff(i + 1011) = 3: ff(i + 1012) = 2: ff(i + 1014) = 2: ff(i + 1015) = 5: ff(i + 1016) = 2: ff(i + 1017) = 3: ff(i + 1018) = 2: ff(i + 1020) = 2: ff(i + 1022) = 2: ff(i + 1023) = 3
    ff(i + 1024) = 2: ff(i + 1025) = 5: ff(i + 1026) = 2: ff(i + 1028) = 2: ff(i + 1029) = 3: ff(i + 1030) = 2: ff(i + 1032) = 2: ff(i + 1034) = 2: ff(i + 1035) = 3: ff(i + 1036) = 2
    ff(i + 1038) = 2: ff(i + 1040) = 2: ff(i + 1041) = 3: ff(i + 1042) = 2: ff(i + 1043) = 7: ff(i + 1044) = 2: ff(i + 1045) = 5: ff(i + 1046) = 2: ff(i + 1047) = 3: ff(i + 1048) = 2
    ff(i + 1050) = 2: ff(i + 1052) = 2: ff(i + 1053) = 3: ff(i + 1054) = 2: ff(i + 1055) = 5: ff(i + 1056) = 2: ff(i + 1057) = 7: ff(i + 1058) = 2: ff(i + 1059) = 3: ff(i + 1060) = 2
    ff(i + 1062) = 2: ff(i + 1064) = 2: ff(i + 1065) = 3: ff(i + 1066) = 2: ff(i + 1067) = 11: ff(i + 1068) = 2: ff(i + 1070) = 2: ff(i + 1071) = 3: ff(i + 1072) = 2: ff(i + 1074) = 2
    ff(i + 1075) = 5: ff(i + 1076) = 2: ff(i + 1077) = 3: ff(i + 1078) = 2: ff(i + 1080) = 2: ff(i + 1082) = 2: ff(i + 1083) = 3: ff(i + 1084) = 2: ff(i + 1085) = 5: ff(i + 1086) = 2
    ff(i + 1088) = 2: ff(i + 1089) = 3: ff(i + 1090) = 2: ff(i + 1092) = 2: ff(i + 1094) = 2: ff(i + 1095) = 3: ff(i + 1096) = 2: ff(i + 1098) = 2: ff(i + 1099) = 7: ff(i + 1100) = 2
    ff(i + 1101) = 3: ff(i + 1102) = 2: ff(i + 1104) = 2: ff(i + 1105) = 5: ff(i + 1106) = 2: ff(i + 1107) = 3: ff(i + 1108) = 2: ff(i + 1110) = 2: ff(i + 1111) = 11: ff(i + 1112) = 2
    ff(i + 1113) = 3: ff(i + 1114) = 2: ff(i + 1115) = 5: ff(i + 1116) = 2: ff(i + 1118) = 2: ff(i + 1119) = 3: ff(i + 1120) = 2: ff(i + 1122) = 2: ff(i + 1124) = 2: ff(i + 1125) = 3
    ff(i + 1126) = 2: ff(i + 1127) = 7: ff(i + 1128) = 2: ff(i + 1130) = 2: ff(i + 1131) = 3: ff(i + 1132) = 2: ff(i + 1133) = 11: ff(i + 1134) = 2: ff(i + 1135) = 5: ff(i + 1136) = 2
    ff(i + 1137) = 3: ff(i + 1138) = 2: ff(i + 1140) = 2: ff(i + 1141) = 7: ff(i + 1142) = 2: ff(i + 1143) = 3: ff(i + 1144) = 2: ff(i + 1145) = 5: ff(i + 1146) = 2: ff(i + 1148) = 2
    ff(i + 1149) = 3: ff(i + 1150) = 2: ff(i + 1152) = 2: ff(i + 1154) = 2: ff(i + 1155) = 3: ff(i + 1156) = 2: ff(i + 1158) = 2: ff(i + 1160) = 2: ff(i + 1161) = 3: ff(i + 1162) = 2
    ff(i + 1164) = 2: ff(i + 1165) = 5: ff(i + 1166) = 2: ff(i + 1167) = 3: ff(i + 1168) = 2: ff(i + 1169) = 7: ff(i + 1170) = 2: ff(i + 1172) = 2: ff(i + 1173) = 3: ff(i + 1174) = 2
    ff(i + 1175) = 5: ff(i + 1176) = 2: ff(i + 1177) = 11: ff(i + 1178) = 2: ff(i + 1179) = 3: ff(i + 1180) = 2: ff(i + 1182) = 2: ff(i + 1183) = 7: ff(i + 1184) = 2: ff(i + 1185) = 3
    ff(i + 1186) = 2: ff(i + 1188) = 2: ff(i + 1190) = 2: ff(i + 1191) = 3: ff(i + 1192) = 2: ff(i + 1194) = 2: ff(i + 1195) = 5: ff(i + 1196) = 2: ff(i + 1197) = 3: ff(i + 1198) = 2
    ff(i + 1199) = 11: ff(i + 1200) = 2: ff(i + 1202) = 2: ff(i + 1203) = 3: ff(i + 1204) = 2: ff(i + 1205) = 5: ff(i + 1206) = 2: ff(i + 1208) = 2: ff(i + 1209) = 3: ff(i + 1210) = 2
    ff(i + 1211) = 7: ff(i + 1212) = 2: ff(i + 1214) = 2: ff(i + 1215) = 3: ff(i + 1216) = 2: ff(i + 1218) = 2: ff(i + 1220) = 2: ff(i + 1221) = 3: ff(i + 1222) = 2: ff(i + 1224) = 2
    ff(i + 1225) = 5: ff(i + 1226) = 2: ff(i + 1227) = 3: ff(i + 1228) = 2: ff(i + 1230) = 2: ff(i + 1232) = 2: ff(i + 1233) = 3: ff(i + 1234) = 2: ff(i + 1235) = 5: ff(i + 1236) = 2
    ff(i + 1238) = 2: ff(i + 1239) = 3: ff(i + 1240) = 2: ff(i + 1242) = 2: ff(i + 1243) = 11: ff(i + 1244) = 2: ff(i + 1245) = 3: ff(i + 1246) = 2: ff(i + 1248) = 2: ff(i + 1250) = 2
    ff(i + 1251) = 3: ff(i + 1252) = 2: ff(i + 1253) = 7: ff(i + 1254) = 2: ff(i + 1255) = 5: ff(i + 1256) = 2: ff(i + 1257) = 3: ff(i + 1258) = 2: ff(i + 1260) = 2: ff(i + 1262) = 2
    ff(i + 1263) = 3: ff(i + 1264) = 2: ff(i + 1265) = 5: ff(i + 1266) = 2: ff(i + 1267) = 7: ff(i + 1268) = 2: ff(i + 1269) = 3: ff(i + 1270) = 2: ff(i + 1272) = 2: ff(i + 1274) = 2
    ff(i + 1275) = 3: ff(i + 1276) = 2: ff(i + 1278) = 2: ff(i + 1280) = 2: ff(i + 1281) = 3: ff(i + 1282) = 2: ff(i + 1284) = 2: ff(i + 1285) = 5: ff(i + 1286) = 2: ff(i + 1287) = 3
    ff(i + 1288) = 2: ff(i + 1290) = 2: ff(i + 1292) = 2: ff(i + 1293) = 3: ff(i + 1294) = 2: ff(i + 1295) = 5: ff(i + 1296) = 2: ff(i + 1298) = 2: ff(i + 1299) = 3: ff(i + 1300) = 2
    ff(i + 1302) = 2: ff(i + 1304) = 2: ff(i + 1305) = 3: ff(i + 1306) = 2: ff(i + 1308) = 2: ff(i + 1309) = 7: ff(i + 1310) = 2: ff(i + 1311) = 3: ff(i + 1312) = 2: ff(i + 1314) = 2
    ff(i + 1315) = 5: ff(i + 1316) = 2: ff(i + 1317) = 3: ff(i + 1318) = 2: ff(i + 1320) = 2: ff(i + 1322) = 2: ff(i + 1323) = 3: ff(i + 1324) = 2: ff(i + 1325) = 5: ff(i + 1326) = 2
    ff(i + 1328) = 2: ff(i + 1329) = 3: ff(i + 1330) = 2: ff(i + 1331) = 11: ff(i + 1332) = 2: ff(i + 1334) = 2: ff(i + 1335) = 3: ff(i + 1336) = 2: ff(i + 1337) = 7: ff(i + 1338) = 2
    ff(i + 1340) = 2: ff(i + 1341) = 3: ff(i + 1342) = 2: ff(i + 1344) = 2: ff(i + 1345) = 5: ff(i + 1346) = 2: ff(i + 1347) = 3: ff(i + 1348) = 2: ff(i + 1350) = 2: ff(i + 1351) = 7
    ff(i + 1352) = 2: ff(i + 1353) = 3: ff(i + 1354) = 2: ff(i + 1355) = 5: ff(i + 1356) = 2: ff(i + 1358) = 2: ff(i + 1359) = 3: ff(i + 1360) = 2: ff(i + 1362) = 2: ff(i + 1364) = 2
    ff(i + 1365) = 3: ff(i + 1366) = 2: ff(i + 1368) = 2: ff(i + 1370) = 2: ff(i + 1371) = 3: ff(i + 1372) = 2: ff(i + 1374) = 2: ff(i + 1375) = 5: ff(i + 1376) = 2: ff(i + 1377) = 3
    ff(i + 1378) = 2: ff(i + 1379) = 7: ff(i + 1380) = 2: ff(i + 1382) = 2: ff(i + 1383) = 3: ff(i + 1384) = 2: ff(i + 1385) = 5: ff(i + 1386) = 2: ff(i + 1388) = 2: ff(i + 1389) = 3
    ff(i + 1390) = 2: ff(i + 1392) = 2: ff(i + 1393) = 7: ff(i + 1394) = 2: ff(i + 1395) = 3: ff(i + 1396) = 2: ff(i + 1397) = 11: ff(i + 1398) = 2: ff(i + 1400) = 2: ff(i + 1401) = 3
    ff(i + 1402) = 2: ff(i + 1404) = 2: ff(i + 1405) = 5: ff(i + 1406) = 2: ff(i + 1407) = 3: ff(i + 1408) = 2: ff(i + 1410) = 2: ff(i + 1412) = 2: ff(i + 1413) = 3: ff(i + 1414) = 2
    ff(i + 1415) = 5: ff(i + 1416) = 2: ff(i + 1418) = 2: ff(i + 1419) = 3: ff(i + 1420) = 2: ff(i + 1421) = 7: ff(i + 1422) = 2: ff(i + 1424) = 2: ff(i + 1425) = 3: ff(i + 1426) = 2
    ff(i + 1428) = 2: ff(i + 1430) = 2: ff(i + 1431) = 3: ff(i + 1432) = 2: ff(i + 1434) = 2: ff(i + 1435) = 5: ff(i + 1436) = 2: ff(i + 1437) = 3: ff(i + 1438) = 2: ff(i + 1440) = 2
    ff(i + 1441) = 11: ff(i + 1442) = 2: ff(i + 1443) = 3: ff(i + 1444) = 2: ff(i + 1445) = 5: ff(i + 1446) = 2: ff(i + 1448) = 2: ff(i + 1449) = 3: ff(i + 1450) = 2: ff(i + 1452) = 2
    ff(i + 1454) = 2: ff(i + 1455) = 3: ff(i + 1456) = 2: ff(i + 1458) = 2: ff(i + 1460) = 2: ff(i + 1461) = 3: ff(i + 1462) = 2: ff(i + 1463) = 7: ff(i + 1464) = 2: ff(i + 1465) = 5
    ff(i + 1466) = 2: ff(i + 1467) = 3: ff(i + 1468) = 2: ff(i + 1470) = 2: ff(i + 1472) = 2: ff(i + 1473) = 3: ff(i + 1474) = 2: ff(i + 1475) = 5: ff(i + 1476) = 2: ff(i + 1477) = 7
    ff(i + 1478) = 2: ff(i + 1479) = 3: ff(i + 1480) = 2: ff(i + 1482) = 2: ff(i + 1484) = 2: ff(i + 1485) = 3: ff(i + 1486) = 2: ff(i + 1488) = 2: ff(i + 1490) = 2: ff(i + 1491) = 3
    ff(i + 1492) = 2: ff(i + 1494) = 2: ff(i + 1495) = 5: ff(i + 1496) = 2: ff(i + 1497) = 3: ff(i + 1498) = 2: ff(i + 1500) = 2: ff(i + 1502) = 2: ff(i + 1503) = 3: ff(i + 1504) = 2
    ff(i + 1505) = 5: ff(i + 1506) = 2: ff(i + 1507) = 11: ff(i + 1508) = 2: ff(i + 1509) = 3: ff(i + 1510) = 2: ff(i + 1512) = 2: ff(i + 1514) = 2: ff(i + 1515) = 3: ff(i + 1516) = 2
    ff(i + 1518) = 2: ff(i + 1519) = 7: ff(i + 1520) = 2: ff(i + 1521) = 3: ff(i + 1522) = 2: ff(i + 1524) = 2: ff(i + 1525) = 5: ff(i + 1526) = 2: ff(i + 1527) = 3: ff(i + 1528) = 2
    ff(i + 1529) = 11: ff(i + 1530) = 2: ff(i + 1532) = 2: ff(i + 1533) = 3: ff(i + 1534) = 2: ff(i + 1535) = 5: ff(i + 1536) = 2: ff(i + 1538) = 2: ff(i + 1539) = 3: ff(i + 1540) = 2
    ff(i + 1542) = 2: ff(i + 1544) = 2: ff(i + 1545) = 3: ff(i + 1546) = 2: ff(i + 1547) = 7: ff(i + 1548) = 2: ff(i + 1550) = 2: ff(i + 1551) = 3: ff(i + 1552) = 2: ff(i + 1554) = 2
    ff(i + 1555) = 5: ff(i + 1556) = 2: ff(i + 1557) = 3: ff(i + 1558) = 2: ff(i + 1560) = 2: ff(i + 1561) = 7: ff(i + 1562) = 2: ff(i + 1563) = 3: ff(i + 1564) = 2: ff(i + 1565) = 5
    ff(i + 1566) = 2: ff(i + 1568) = 2: ff(i + 1569) = 3: ff(i + 1570) = 2: ff(i + 1572) = 2: ff(i + 1573) = 11: ff(i + 1574) = 2: ff(i + 1575) = 3: ff(i + 1576) = 2: ff(i + 1578) = 2
    ff(i + 1580) = 2: ff(i + 1581) = 3: ff(i + 1582) = 2: ff(i + 1584) = 2: ff(i + 1585) = 5: ff(i + 1586) = 2: ff(i + 1587) = 3: ff(i + 1588) = 2: ff(i + 1589) = 7: ff(i + 1590) = 2
    ff(i + 1592) = 2: ff(i + 1593) = 3: ff(i + 1594) = 2: ff(i + 1595) = 5: ff(i + 1596) = 2: ff(i + 1598) = 2: ff(i + 1599) = 3: ff(i + 1600) = 2: ff(i + 1602) = 2: ff(i + 1603) = 7
    ff(i + 1604) = 2: ff(i + 1605) = 3: ff(i + 1606) = 2: ff(i + 1608) = 2: ff(i + 1610) = 2: ff(i + 1611) = 3: ff(i + 1612) = 2: ff(i + 1614) = 2: ff(i + 1615) = 5: ff(i + 1616) = 2
    ff(i + 1617) = 3: ff(i + 1618) = 2: ff(i + 1620) = 2: ff(i + 1622) = 2: ff(i + 1623) = 3: ff(i + 1624) = 2: ff(i + 1625) = 5: ff(i + 1626) = 2: ff(i + 1628) = 2: ff(i + 1629) = 3
    ff(i + 1630) = 2: ff(i + 1631) = 7: ff(i + 1632) = 2: ff(i + 1634) = 2: ff(i + 1635) = 3: ff(i + 1636) = 2: ff(i + 1638) = 2: ff(i + 1639) = 11: ff(i + 1640) = 2: ff(i + 1641) = 3
    ff(i + 1642) = 2: ff(i + 1644) = 2: ff(i + 1645) = 5: ff(i + 1646) = 2: ff(i + 1647) = 3: ff(i + 1648) = 2: ff(i + 1650) = 2: ff(i + 1652) = 2: ff(i + 1653) = 3: ff(i + 1654) = 2
    ff(i + 1655) = 5: ff(i + 1656) = 2: ff(i + 1658) = 2: ff(i + 1659) = 3: ff(i + 1660) = 2: ff(i + 1661) = 11: ff(i + 1662) = 2: ff(i + 1664) = 2: ff(i + 1665) = 3: ff(i + 1666) = 2
    ff(i + 1668) = 2: ff(i + 1670) = 2: ff(i + 1671) = 3: ff(i + 1672) = 2: ff(i + 1673) = 7: ff(i + 1674) = 2: ff(i + 1675) = 5: ff(i + 1676) = 2: ff(i + 1677) = 3: ff(i + 1678) = 2
    ff(i + 1680) = 2: ff(i + 1682) = 2: ff(i + 1683) = 3: ff(i + 1684) = 2: ff(i + 1685) = 5: ff(i + 1686) = 2: ff(i + 1687) = 7: ff(i + 1688) = 2: ff(i + 1689) = 3: ff(i + 1690) = 2
    ff(i + 1692) = 2: ff(i + 1694) = 2: ff(i + 1695) = 3: ff(i + 1696) = 2: ff(i + 1698) = 2: ff(i + 1700) = 2: ff(i + 1701) = 3: ff(i + 1702) = 2: ff(i + 1704) = 2: ff(i + 1705) = 5
    ff(i + 1706) = 2: ff(i + 1707) = 3: ff(i + 1708) = 2: ff(i + 1710) = 2: ff(i + 1712) = 2: ff(i + 1713) = 3: ff(i + 1714) = 2: ff(i + 1715) = 5: ff(i + 1716) = 2: ff(i + 1718) = 2
    ff(i + 1719) = 3: ff(i + 1720) = 2: ff(i + 1722) = 2: ff(i + 1724) = 2: ff(i + 1725) = 3: ff(i + 1726) = 2: ff(i + 1727) = 11: ff(i + 1728) = 2: ff(i + 1729) = 7: ff(i + 1730) = 2
    ff(i + 1731) = 3: ff(i + 1732) = 2: ff(i + 1734) = 2: ff(i + 1735) = 5: ff(i + 1736) = 2: ff(i + 1737) = 3: ff(i + 1738) = 2: ff(i + 1740) = 2: ff(i + 1742) = 2: ff(i + 1743) = 3
    ff(i + 1744) = 2: ff(i + 1745) = 5: ff(i + 1746) = 2: ff(i + 1748) = 2: ff(i + 1749) = 3: ff(i + 1750) = 2: ff(i + 1752) = 2: ff(i + 1754) = 2: ff(i + 1755) = 3: ff(i + 1756) = 2
    ff(i + 1757) = 7: ff(i + 1758) = 2: ff(i + 1760) = 2: ff(i + 1761) = 3: ff(i + 1762) = 2: ff(i + 1764) = 2: ff(i + 1765) = 5: ff(i + 1766) = 2: ff(i + 1767) = 3: ff(i + 1768) = 2
    ff(i + 1770) = 2: ff(i + 1771) = 7: ff(i + 1772) = 2: ff(i + 1773) = 3: ff(i + 1774) = 2: ff(i + 1775) = 5: ff(i + 1776) = 2: ff(i + 1778) = 2: ff(i + 1779) = 3: ff(i + 1780) = 2
    ff(i + 1782) = 2: ff(i + 1784) = 2: ff(i + 1785) = 3: ff(i + 1786) = 2: ff(i + 1788) = 2: ff(i + 1790) = 2: ff(i + 1791) = 3: ff(i + 1792) = 2: ff(i + 1793) = 11: ff(i + 1794) = 2
    ff(i + 1795) = 5: ff(i + 1796) = 2: ff(i + 1797) = 3: ff(i + 1798) = 2: ff(i + 1799) = 7: ff(i + 1800) = 2: ff(i + 1802) = 2: ff(i + 1803) = 3: ff(i + 1804) = 2: ff(i + 1805) = 5
    ff(i + 1806) = 2: ff(i + 1808) = 2: ff(i + 1809) = 3: ff(i + 1810) = 2: ff(i + 1812) = 2: ff(i + 1813) = 7: ff(i + 1814) = 2: ff(i + 1815) = 3: ff(i + 1816) = 2: ff(i + 1818) = 2
    ff(i + 1820) = 2: ff(i + 1821) = 3: ff(i + 1822) = 2: ff(i + 1824) = 2: ff(i + 1825) = 5: ff(i + 1826) = 2: ff(i + 1827) = 3: ff(i + 1828) = 2: ff(i + 1830) = 2: ff(i + 1832) = 2
    ff(i + 1833) = 3: ff(i + 1834) = 2: ff(i + 1835) = 5: ff(i + 1836) = 2: ff(i + 1837) = 11: ff(i + 1838) = 2: ff(i + 1839) = 3: ff(i + 1840) = 2: ff(i + 1841) = 7: ff(i + 1842) = 2
    ff(i + 1844) = 2: ff(i + 1845) = 3: ff(i + 1846) = 2: ff(i + 1848) = 2: ff(i + 1850) = 2: ff(i + 1851) = 3: ff(i + 1852) = 2: ff(i + 1854) = 2: ff(i + 1855) = 5: ff(i + 1856) = 2
    ff(i + 1857) = 3: ff(i + 1858) = 2: ff(i + 1859) = 11: ff(i + 1860) = 2: ff(i + 1862) = 2: ff(i + 1863) = 3: ff(i + 1864) = 2: ff(i + 1865) = 5: ff(i + 1866) = 2: ff(i + 1868) = 2
    ff(i + 1869) = 3: ff(i + 1870) = 2: ff(i + 1872) = 2: ff(i + 1874) = 2: ff(i + 1875) = 3: ff(i + 1876) = 2: ff(i + 1878) = 2: ff(i + 1880) = 2: ff(i + 1881) = 3: ff(i + 1882) = 2
    ff(i + 1883) = 7: ff(i + 1884) = 2: ff(i + 1885) = 5: ff(i + 1886) = 2: ff(i + 1887) = 3: ff(i + 1888) = 2: ff(i + 1890) = 2: ff(i + 1892) = 2: ff(i + 1893) = 3: ff(i + 1894) = 2
    ff(i + 1895) = 5: ff(i + 1896) = 2: ff(i + 1897) = 7: ff(i + 1898) = 2: ff(i + 1899) = 3: ff(i + 1900) = 2: ff(i + 1902) = 2: ff(i + 1903) = 11: ff(i + 1904) = 2: ff(i + 1905) = 3
    ff(i + 1906) = 2: ff(i + 1908) = 2: ff(i + 1910) = 2: ff(i + 1911) = 3: ff(i + 1912) = 2: ff(i + 1914) = 2: ff(i + 1915) = 5: ff(i + 1916) = 2: ff(i + 1917) = 3: ff(i + 1918) = 2
    ff(i + 1920) = 2: ff(i + 1922) = 2: ff(i + 1923) = 3: ff(i + 1924) = 2: ff(i + 1925) = 5: ff(i + 1926) = 2: ff(i + 1928) = 2: ff(i + 1929) = 3: ff(i + 1930) = 2: ff(i + 1932) = 2
    ff(i + 1934) = 2: ff(i + 1935) = 3: ff(i + 1936) = 2: ff(i + 1938) = 2: ff(i + 1939) = 7: ff(i + 1940) = 2: ff(i + 1941) = 3: ff(i + 1942) = 2: ff(i + 1944) = 2: ff(i + 1945) = 5
    ff(i + 1946) = 2: ff(i + 1947) = 3: ff(i + 1948) = 2: ff(i + 1950) = 2: ff(i + 1952) = 2: ff(i + 1953) = 3: ff(i + 1954) = 2: ff(i + 1955) = 5: ff(i + 1956) = 2: ff(i + 1958) = 2
    ff(i + 1959) = 3: ff(i + 1960) = 2: ff(i + 1962) = 2: ff(i + 1964) = 2: ff(i + 1965) = 3: ff(i + 1966) = 2: ff(i + 1967) = 7: ff(i + 1968) = 2: ff(i + 1969) = 11: ff(i + 1970) = 2
    ff(i + 1971) = 3: ff(i + 1972) = 2: ff(i + 1974) = 2: ff(i + 1975) = 5: ff(i + 1976) = 2: ff(i + 1977) = 3: ff(i + 1978) = 2: ff(i + 1980) = 2: ff(i + 1981) = 7: ff(i + 1982) = 2
    ff(i + 1983) = 3: ff(i + 1984) = 2: ff(i + 1985) = 5: ff(i + 1986) = 2: ff(i + 1988) = 2: ff(i + 1989) = 3: ff(i + 1990) = 2: ff(i + 1991) = 11: ff(i + 1992) = 2: ff(i + 1994) = 2
    ff(i + 1995) = 3: ff(i + 1996) = 2: ff(i + 1998) = 2: ff(i + 2000) = 2: ff(i + 2001) = 3: ff(i + 2002) = 2: ff(i + 2004) = 2: ff(i + 2005) = 5: ff(i + 2006) = 2: ff(i + 2007) = 3
    ff(i + 2008) = 2: ff(i + 2009) = 7: ff(i + 2010) = 2: ff(i + 2012) = 2: ff(i + 2013) = 3: ff(i + 2014) = 2: ff(i + 2015) = 5: ff(i + 2016) = 2: ff(i + 2018) = 2: ff(i + 2019) = 3
    ff(i + 2020) = 2: ff(i + 2022) = 2: ff(i + 2023) = 7: ff(i + 2024) = 2: ff(i + 2025) = 3: ff(i + 2026) = 2: ff(i + 2028) = 2: ff(i + 2030) = 2: ff(i + 2031) = 3: ff(i + 2032) = 2
    ff(i + 2034) = 2: ff(i + 2035) = 5: ff(i + 2036) = 2: ff(i + 2037) = 3: ff(i + 2038) = 2: ff(i + 2040) = 2: ff(i + 2042) = 2: ff(i + 2043) = 3: ff(i + 2044) = 2: ff(i + 2045) = 5
    ff(i + 2046) = 2: ff(i + 2048) = 2: ff(i + 2049) = 3: ff(i + 2050) = 2: ff(i + 2051) = 7: ff(i + 2052) = 2: ff(i + 2054) = 2: ff(i + 2055) = 3: ff(i + 2056) = 2: ff(i + 2057) = 11
    ff(i + 2058) = 2: ff(i + 2060) = 2: ff(i + 2061) = 3: ff(i + 2062) = 2: ff(i + 2064) = 2: ff(i + 2065) = 5: ff(i + 2066) = 2: ff(i + 2067) = 3: ff(i + 2068) = 2: ff(i + 2070) = 2
    ff(i + 2072) = 2: ff(i + 2073) = 3: ff(i + 2074) = 2: ff(i + 2075) = 5: ff(i + 2076) = 2: ff(i + 2078) = 2: ff(i + 2079) = 3: ff(i + 2080) = 2: ff(i + 2082) = 2: ff(i + 2084) = 2
    ff(i + 2085) = 3: ff(i + 2086) = 2: ff(i + 2088) = 2: ff(i + 2090) = 2: ff(i + 2091) = 3: ff(i + 2092) = 2: ff(i + 2093) = 7: ff(i + 2094) = 2: ff(i + 2095) = 5: ff(i + 2096) = 2
    ff(i + 2097) = 3: ff(i + 2098) = 2: ff(i + 2100) = 2: ff(i + 2101) = 11: ff(i + 2102) = 2: ff(i + 2103) = 3: ff(i + 2104) = 2: ff(i + 2105) = 5: ff(i + 2106) = 2: ff(i + 2107) = 7
    ff(i + 2108) = 2: ff(i + 2109) = 3: ff(i + 2110) = 2: ff(i + 2112) = 2: ff(i + 2114) = 2: ff(i + 2115) = 3: ff(i + 2116) = 2: ff(i + 2118) = 2: ff(i + 2120) = 2: ff(i + 2121) = 3
    ff(i + 2122) = 2: ff(i + 2123) = 11: ff(i + 2124) = 2: ff(i + 2125) = 5: ff(i + 2126) = 2: ff(i + 2127) = 3: ff(i + 2128) = 2: ff(i + 2130) = 2: ff(i + 2132) = 2: ff(i + 2133) = 3
    ff(i + 2134) = 2: ff(i + 2135) = 5: ff(i + 2136) = 2: ff(i + 2138) = 2: ff(i + 2139) = 3: ff(i + 2140) = 2: ff(i + 2142) = 2: ff(i + 2144) = 2: ff(i + 2145) = 3: ff(i + 2146) = 2
    ff(i + 2148) = 2: ff(i + 2149) = 7: ff(i + 2150) = 2: ff(i + 2151) = 3: ff(i + 2152) = 2: ff(i + 2154) = 2: ff(i + 2155) = 5: ff(i + 2156) = 2: ff(i + 2157) = 3: ff(i + 2158) = 2
    ff(i + 2160) = 2: ff(i + 2162) = 2: ff(i + 2163) = 3: ff(i + 2164) = 2: ff(i + 2165) = 5: ff(i + 2166) = 2: ff(i + 2167) = 11: ff(i + 2168) = 2: ff(i + 2169) = 3: ff(i + 2170) = 2
    ff(i + 2172) = 2: ff(i + 2174) = 2: ff(i + 2175) = 3: ff(i + 2176) = 2: ff(i + 2177) = 7: ff(i + 2178) = 2: ff(i + 2180) = 2: ff(i + 2181) = 3: ff(i + 2182) = 2: ff(i + 2184) = 2
    ff(i + 2185) = 5: ff(i + 2186) = 2: ff(i + 2187) = 3: ff(i + 2188) = 2: ff(i + 2189) = 11: ff(i + 2190) = 2: ff(i + 2191) = 7: ff(i + 2192) = 2: ff(i + 2193) = 3: ff(i + 2194) = 2
    ff(i + 2195) = 5: ff(i + 2196) = 2: ff(i + 2198) = 2: ff(i + 2199) = 3: ff(i + 2200) = 2: ff(i + 2202) = 2: ff(i + 2204) = 2: ff(i + 2205) = 3: ff(i + 2206) = 2: ff(i + 2208) = 2
    ff(i + 2210) = 2: ff(i + 2211) = 3: ff(i + 2212) = 2: ff(i + 2214) = 2: ff(i + 2215) = 5: ff(i + 2216) = 2: ff(i + 2217) = 3: ff(i + 2218) = 2: ff(i + 2219) = 7: ff(i + 2220) = 2
    ff(i + 2222) = 2: ff(i + 2223) = 3: ff(i + 2224) = 2: ff(i + 2225) = 5: ff(i + 2226) = 2: ff(i + 2228) = 2: ff(i + 2229) = 3: ff(i + 2230) = 2: ff(i + 2232) = 2: ff(i + 2233) = 7
    ff(i + 2234) = 2: ff(i + 2235) = 3: ff(i + 2236) = 2: ff(i + 2238) = 2: ff(i + 2240) = 2: ff(i + 2241) = 3: ff(i + 2242) = 2: ff(i + 2244) = 2: ff(i + 2245) = 5: ff(i + 2246) = 2
    ff(i + 2247) = 3: ff(i + 2248) = 2: ff(i + 2250) = 2: ff(i + 2252) = 2: ff(i + 2253) = 3: ff(i + 2254) = 2: ff(i + 2255) = 5: ff(i + 2256) = 2: ff(i + 2258) = 2: ff(i + 2259) = 3
    ff(i + 2260) = 2: ff(i + 2261) = 7: ff(i + 2262) = 2: ff(i + 2264) = 2: ff(i + 2265) = 3: ff(i + 2266) = 2: ff(i + 2268) = 2: ff(i + 2270) = 2: ff(i + 2271) = 3: ff(i + 2272) = 2
    ff(i + 2274) = 2: ff(i + 2275) = 5: ff(i + 2276) = 2: ff(i + 2277) = 3: ff(i + 2278) = 2: ff(i + 2280) = 2: ff(i + 2282) = 2: ff(i + 2283) = 3: ff(i + 2284) = 2: ff(i + 2285) = 5
    ff(i + 2286) = 2: ff(i + 2288) = 2: ff(i + 2289) = 3: ff(i + 2290) = 2: ff(i + 2292) = 2: ff(i + 2294) = 2: ff(i + 2295) = 3: ff(i + 2296) = 2: ff(i + 2298) = 2: ff(i + 2299) = 11
    ff(i + 2300) = 2: ff(i + 2301) = 3: ff(i + 2302) = 2: ff(i + 2303) = 7: ff(i + 2304) = 2: ff(i + 2305) = 5: ff(i + 2306) = 2: ff(i + 2307) = 3: ff(i + 2308) = 2: ff(i + 2310) = 2
Next
ff(2) = 0: ff(3) = 0: ff(5) = 0: ff(7) = 0: ff(11) = 0 'fix first primes
For pcand = 13 To testlimitN Step 2
    If ff(pcand) = 0 Then
        'v2 line that made big difference i starts at pcand squared and steps by twice pcand
        For i = pcand * pcand To topN Step 2 * pcand
            If ff(i) = 0 Then ff(i) = pcand
        Next
    End If
Next

'count primes
For i = 2 To topN
    If ff(i) = 0 Then p = p + 1
Next
tStop# = Timer(.001)
tTime# = tStop# - tStart#
Print "For "; topN; " numbers there are "; p; " primes in "; tTime#; " secs."

For i = 1000 To topN
    If ff(i) = 0 Then
        sp$ = _Trim$(Str$(i)): b$ = ""
        For j = 1 To Len(sp$)
            b$ = Mid$(sp$, j, 1) + b$
        Next
        If Val(b$) = i Then Pals = Pals + 1: Print Pals, i
    End If
Next
Print "Total Palindromes found ="; Pals
'test some factoring of numbers
'factorMe = 10
'While factorMe > 1
'    Input "Enter a number to factor, 0 quits "; factorMe
'    If factorMe < 2 Then Exit While Else Print factors$(factorMe)
'Wend

Function factors$ (n)
    If n > topN Then factors$ = "Error: too high a number.": Exit Function
    f$ = ""
    While ff(n) <> 0
        f$ = f$ + Str$(ff(n)) + " "
        n = n / ff(n)
    Wend
    factors$ = f$ + Str$(n)
End Function
b = b + ...
Reply
#3
From 10 to 100,000,000 777 Palindrome Primes which is a Palindrome Number (but not prime).

Wow that code used to take nearly 30 secs to find 5,761,455 primes in first 100,000,000 integers now it's 3 secs!
b = b + ...
Reply
#4
Fascinating! There is only one palindromic prime with an even number of digits. No idea why this should be so.
[edit]... I get it now all even numbered palindromes are divisible by 11 (even 11 which is prime).
Reply
#5
@david_uwi   ' << sorry refuses to tag for me sometimes if I fiddle enough it will

Interesting indeed! Only one with even number of digits? What was it?

How were able to rule out numbers of the form 1 (<n amount zeroes>) 1 ie 1 on both ends and any amount of zeroes in between?

Update: What was I thinking??? If you could multiply by a number then it's not prime to begin with!
b = b + ...
Reply
#6
I wonder if it's true that a palindromic number to any base N with an even number of digits is divisible by N+1.
Hexadecimal say 1AA1 (6817 dec) is divisible by 11 (hex) 17(dec). So just like in decimal 11 is the only even digit number palindrome that is prime. I guess for an odd number base it may not be true, but I can't be bothered to check.
Reply




Users browsing this thread: 1 Guest(s)