
#include "mod/divisors.h"

#include "demo/nextarg.h"
#include "fxtio.h"

//% List all divisors of an integer


//#define TIMING // uncomment to disable printing


int
main(int argc, char **argv)
{
#ifndef TIMING
    umod_t n =  2*3*3*5*7;
#else
    ulong n = 614889782588491410ULL; // == 2*3*5*7*11*...*43*47
#endif
    NXARG(n, "Number whose divisors shall be listed");

    divisors D(n);

    cout << " primes    = [";
    for (int j=0; j<D.n_; ++j)  cout << setw(3) << D.p_[j] << " ";
    cout << " ]";
    cout << endl;
    cout << " exponents = [";
    for (int j=0; j<D.n_; ++j)  cout << setw(3) << D.mr_->m1_[j] << " ";
    cout << " ]";
    cout << endl;
    cout << endl;


    ulong d = D.first();
    ulong ct = 0;
    do
    {
        ++ct;
#ifndef TIMING
        cout << setw(3) << ct << ":  ";
        cout << setw(6) << d;

        cout << "   t=[";
        for (int j=0; j<=D.n_; ++j)  cout << setw(4) << D.t_[j];
        cout << " ]";

        cout << "   mr=[";
        for (int j=0; j<D.n_; ++j)  cout << setw(2) << D.mr_->a_[j];
        cout << " ]";

        cout << "   j = " << D.mr_->j_;

        cout << endl;
#endif  // TIMING
    }
    while ( ( d=D.next() ) );

    cout << " #= " << ct << endl;

    return 0;
}
// -------------------------

/*
Timing:

% time ./bin
arg 1: 614889782588491410 == n  [Number whose divisors shall be listed]
 primes    = [   2    3    5    7   11   13   17   19   23   29   31   37   41   43   47  ]
 exponents = [   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 ]

 #= 32768
./bin  0.00s user 0.00s system 88% cpu 0.003 total
that is, the computation cost can be neglected

*/


/// Emacs:
/// Local Variables:
/// MyRelDir: "demo/mod"
/// makefile-dir: "../../"
/// make-target: "1demo DSRC=demo/mod/divisors-demo.cc"
/// make-target2: "1demo DSRC=demo/mod/divisors-demo.cc DEMOFLAGS=-DTIMING"
/// End:
