login
This site is supported by donations to The OEIS Foundation.
Logo

Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A054797 Smallest prime number whose digits sum to n-th palindromic prime. 0
2, 3, 5, 7, 29, 399999998999, 789989999999999, 89989999999999999, 299999899999999999999, 4899999999989999999999, 88999999999999999999999999999999999, 3999899999999999999999999999999999999999, 689999999999999999999999999999999989999999, 6999989999999999999999999999999999999999999 (list; graph; refs; listen; history; internal format)
OFFSET

1,1

LINKS

Factorization using the Elliptic Curve Method

PROG

//The following program was coded by David Consiglio, Jr.

#include <iostream>

#include <conio.h>

#include <string>

#include <fstream>

#include <sstream>

#include <algorithm>

using namespace std;

string cand = "";

string max_cand = "";

int inc_pos = 0;

int first_pos = 0;

int sum = 101;

int test_sum = 0;

int counter = 1;

int e_pos = 0;

fstream out1;

int inc(int pos)

    {

    cand[pos]++;

    cand[pos+1]--;

    }

int generate()

    {

    int a = sum/9;

    int b = sum % 9;

    cand += char(b+48);

    for(int q = 0; q < a; q++)

        {

        cand += '9';

        }

    max_cand = cand;

    max_cand[max_cand.length()-1] = cand[0];

    max_cand[0] = '9';

    }

int locate()

{

    for(int a = 0; a < cand.length()-1; a++)

    {

        if(cand[a] != '9')

        {

            inc_pos = a;

            //cout << inc_pos << " ";

        }

    }

}

int rev_loc()

{

    for(int a = cand.length()-2; a >= 0; a--)//search backwards for first non-9

    {

        if(cand[a] != '9')

        {

            first_pos = a;

            a = 0;

            //cout << "reverting to: " << first_pos << " ";

        }

    }

}

int main()

    {

    int steps = 0;

    bool step_flag = true;

    cout << "Palindromic Prime? ";

    cin >> sum;

    out1.open("candidates.txt", ios::out);

    cout << "Display each ___ candidates. (0 for none, 1 for all, 10 for every 10th, etc.)" << endl;

    cout << "Warning: Selecting 1 will result in slow execution for certain large primes." << endl;

    cin >> steps;

    if(steps == 0)

    {

             step_flag = false;

             }

    generate(); //determines lowest and highest candidates

    cout << counter << " " << cand << endl;

    out1 << cand << endl;

    cand[0]++; //increment to 2nd lowest candidate (special case)

    cand[1]--;

    counter++;

    if(steps == 1)

        {

        cout << counter << " " << cand << endl;

        }

    out1 << cand << endl;

    while(cand < max_cand)

        {

        while(cand[cand.length()-1] == '9')//we are iterating through a run of 89 swaps

            {

            locate();

            inc(inc_pos);

            counter++;

            if(step_flag && counter % steps == 0)

                {

                cout << counter << " " << cand << endl;

                }

            out1 << cand << endl;

            }

        rev_loc(); //undo all of the swaps

        cand[first_pos]++; //increase the last non-9 number

        cand[first_pos+1] = cand[cand.length()-1]; //put the last digit

        cand[first_pos+1]--;

        if(first_pos+1 != cand.length()-1)

            {

                cand[cand.length()-1] = '9'; //put the last 9 back

            }

        counter++;

        if(step_flag && counter % steps == 0)

        {

        cout << counter << " " << cand << endl;

        }

        out1 << cand << endl;

        test_sum = 0;

        }

out1.close();

cout << "Finished at: " << counter << " " << cand << endl;

_getch();

    }

CROSSREFS

Cf. A000040, A002385, A054750.

Sequence in context: A048404 A052013 A174536 * A052014 A090711 A067907

Adjacent sequences:  A054794 A054795 A054796 * A054798 A054799 A054800

KEYWORD

base,more,nonn

AUTHOR

G. L. Honaker, Jr. (honak3r(AT)gmail.com), Apr 27 2000

EXTENSIONS

a(6) added by Carlos B. Rivera F. (crivera(AT)primepuzzles.net).

a(7) from David Consiglio, Jr. (davecons(AT)gmail.com) Nov 07 2011

a(8) - a(15) from David Consiglio, Jr. (davecons(AT)gmail.com) Nov 16 2011

c++ program for listing candidates in numerical order from David Consiglio, Jr. (davecons(AT)gmail.com) Nov 16 2011

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Transforms | Puzzles | Hot | Classics
Recent Additions | More pages | Superseeker | Maintained by The OEIS Foundation Inc.

Content is available under The OEIS End-User License Agreement .

Last modified February 13 15:00 EST 2012. Contains 205519 sequences.