예제 #1
0
파일: 293.cpp 프로젝트: grokus/exp
int
main (int argc, char *argv[])
{
    overall.resize(NMAX + 1);
    b1.resize(NMAX + 1);
    b2.resize(NMAX + 1);
    gen_admissible();
    print_bitset(overall, 640);
    mpz_class p_prev = 0, p = 3;
    mpz_class max;
    mpz_set_ui(max.get_mpz_t(), NMAX);
    size_t pos = overall.find_first();
    Bits pf;
    pf.resize(1000);
    while (pos != string::npos && p_prev < max)
    {
        mpz_swap(p_prev.get_mpz_t(), p.get_mpz_t());
        mpz_nextprime(p.get_mpz_t(), p_prev.get_mpz_t());
        //cout << "next prime: " << p << endl;
        unsigned uip = mpz_get_ui(p.get_mpz_t());
        while (pos != string::npos && pos + 1 < uip)
        {
            pf.set(uip - pos);
            //cout << "pos: " << pos << ", total: " << total << endl;
            pos = overall.find_next(pos);
        }
    }
    unsigned total = 0;
    for (size_t pos = pf.find_first(); pos != string::npos; pos = pf.find_next(pos))
    {
        total += pos;
    }
    cout << "total: " << total << endl;
    return 0;
}
예제 #2
0
파일: 293.cpp 프로젝트: grokus/exp
void
gen_admissible()
{
    unsigned n = 2;
    while (n < NMAX)
    {
        b1.set(n);
        n *= 2;
    }
    overall |= b1;
    for (int i = 0; i < num_primes; i++)
    {
        uint64 p = primes[i];
        do
        {
            size_t pos = b1.find_first();
            uint64 j;
            while (pos != string::npos && (j = pos * p) < NMAX)
            {
                //cout << j << endl;
                b2.set(j);
                pos = b1.find_next(pos);
            }
            p *= primes[i];
        } while (p < NMAX);
        overall |= b2;
        b1.clear();
        b1.resize(NMAX + 1);
        b1.swap(b2);
    }
}
예제 #3
0
파일: 293.cpp 프로젝트: grokus/exp
void
print_bitset(Bits b, size_t size = 0)
{
    if (size == 0)
        size = b.size();
    for (size_t pos = b.find_first(); pos < size && pos != string::npos; pos = b.find_next(pos))
    {
        std::cout << pos << ", ";
    }
    std::cout << std::endl;
}