Problem27

#include <iostream>
#include <cmath>
using namespace std;

#define TLEN  2001000
#define LMTAB 1000
#define LMTN  10

// 素数テーブルの作成
void
primeTable(bool t_prime[])
{
    unsigned int size = (unsigned int)ceil(sqrt((double)TLEN)); // 篩の大きさ

    // 篩にかける
    t_prime[0] = t_prime[1] = false;
    for (unsigned int i = 2; i <= size; i++)
    {
        if (t_prime[i])
        {
            for (unsigned int j = i+i; j < TLEN; j+=i)
            {
                t_prime[j] = false;
            }
        }
    }

    
}

int
main(int argc, char **argv)
{
    int ans = 0;
    int max = -1;

    bool *t_prime = new bool [TLEN];
    memset(t_prime, true, TLEN);
    primeTable(t_prime);

    int b = 1;
    while (b < LMTAB)
    {
        b++;

        if (!t_prime[b])
        {
            continue;
        }
        int a = LMTAB*(-1) + 1;

        while (a < LMTAB)
        {
            if (a + b + 1 < 0)
            {
                a++;
                continue;
            }

            int l = 0;
            for (int n = 0; ; n++)
            {
                int i = n*n + a*n + b;
                if (i < 0 || !t_prime[i])
                {
                    break;
                }
                l++;
            }
            if (max < l)
            {
                max = l;
                ans = a*b;
            }

            a++;
        }

        b++;
    }

    cout << ans << endl;
    
    return 0;
}