1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Copyright (C) 2011, 2012 Sebastian Pancratz
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "longlong.h"
#include "padic.h"
slong * _padic_lifts_exps(slong *n, slong N)
{
slong *a, i;
*n = FLINT_CLOG2(N) + 1;
a = flint_malloc((*n) * sizeof(slong));
for (a[i = 0] = N; a[i] > 1; i++)
a[i + 1] = (a[i] + 1) / 2;
return a;
}
void _padic_lifts_pows(fmpz *pow, const slong *a, slong n, const fmpz_t p)
{
if (n == 1)
{
fmpz_set(pow + 0, p);
}
else /* n > 1 */
{
slong i = n - 1;
fmpz_t t = {WORD(1)};
fmpz_set(pow + i, p);
for (i--; i >= 1; i--)
{
if (a[i] & WORD(1))
{
fmpz_mul(pow + i, t, pow + (i + 1));
fmpz_mul(t, t, t);
}
else
{
fmpz_mul(t, t, pow + (i + 1));
fmpz_mul(pow + i, pow + (i + 1), pow + (i + 1));
}
}
{
if (a[i] & WORD(1))
fmpz_mul(pow + i, t, pow + (i + 1));
else
fmpz_mul(pow + i, pow + (i + 1), pow + (i + 1));
}
fmpz_clear(t);
}
}