2016-03-17 17:27:28 +01:00
|
|
|
/*=============================================================================
|
|
|
|
|
|
|
|
This file is part of ARB.
|
|
|
|
|
|
|
|
ARB is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ARB is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with ARB; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
=============================================================================*/
|
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
Copyright (C) 2016 Pascal Molin
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "dlog.h"
|
|
|
|
|
2016-03-20 22:32:47 +01:00
|
|
|
/* assume non invertible and 1 mod n already set */
|
2016-03-17 17:27:28 +01:00
|
|
|
void
|
2016-03-21 16:55:43 +01:00
|
|
|
dlog_vec_eratos_add(ulong *v, ulong nv, ulong a, ulong va, nmod_t mod, ulong na, nmod_t order)
|
2016-03-17 17:27:28 +01:00
|
|
|
{
|
2016-03-20 22:32:47 +01:00
|
|
|
ulong p, k, n;
|
2016-03-17 17:27:28 +01:00
|
|
|
dlog_precomp_t pre;
|
|
|
|
n_primes_t iter;
|
|
|
|
|
|
|
|
/* discrete log on primes */
|
2016-03-20 22:32:47 +01:00
|
|
|
n = (nv < mod.n) ? nv : mod.n;
|
|
|
|
dlog_precomp_n_init(pre, a, mod.n, na, n_prime_pi(n));
|
2016-03-17 17:27:28 +01:00
|
|
|
|
|
|
|
n_primes_init(iter);
|
2016-03-29 12:52:26 +01:00
|
|
|
|
2016-03-20 22:32:47 +01:00
|
|
|
while ((p = n_primes_next(iter)) < n)
|
2016-03-29 12:52:26 +01:00
|
|
|
{
|
|
|
|
ulong wp, pe;
|
|
|
|
|
2016-03-21 16:55:43 +01:00
|
|
|
if (v[p] == DLOG_NOT_FOUND)
|
2016-03-17 17:27:28 +01:00
|
|
|
continue; /* won't be attained another time */
|
2016-03-21 16:55:43 +01:00
|
|
|
wp = nmod_mul(dlog_precomp(pre, p), va, order);
|
2016-03-29 12:52:26 +01:00
|
|
|
|
|
|
|
/* FIXME: could be faster sieving m*pe? but cannot
|
2016-03-21 16:55:43 +01:00
|
|
|
* use v[p*m]=v[p]*v[m]... */
|
|
|
|
for (pe = p; pe < n; pe *= p)
|
|
|
|
for (k = pe; k < n; k += pe)
|
|
|
|
if (v[k] != DLOG_NOT_FOUND)
|
2016-03-20 22:32:47 +01:00
|
|
|
v[k] = nmod_add(v[k], wp, order);
|
2016-03-29 12:52:26 +01:00
|
|
|
|
2016-03-17 17:27:28 +01:00
|
|
|
}
|
2016-03-29 12:52:26 +01:00
|
|
|
|
2016-03-17 17:27:28 +01:00
|
|
|
n_primes_clear(iter);
|
2016-03-29 12:52:26 +01:00
|
|
|
|
2016-03-20 22:32:47 +01:00
|
|
|
for (k = mod.n + 1; k < nv; k++)
|
|
|
|
v[k] = v[k - mod.n];
|
2016-03-17 17:27:28 +01:00
|
|
|
}
|