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
63
64
65
66
67
68
69
70
71
72
73
74
/*
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 "padic.h"
ulong padic_val_fac_ui_2(ulong N)
{
ulong s = 0, t = N;
do
{
t /= 2;
s += t;
}
while (t);
return s;
}
ulong padic_val_fac_ui(ulong N, const fmpz_t prime)
{
if (fmpz_abs_fits_ui(prime))
{
const ulong p = fmpz_get_ui(prime);
ulong s = 0, t = N;
do
{
t /= p;
s += t;
}
while (t);
return s;
}
else
{
return 0;
}
}
void padic_val_fac(fmpz_t rop, const fmpz_t op, const fmpz_t p)
{
fmpz_t s, t;
if (fmpz_sgn(op) < 0)
{
flint_throw(FLINT_ERROR, "Exception (padic_val_fac). op is negative.\n");
}
fmpz_init(s);
fmpz_init_set(t, op);
do
{
fmpz_fdiv_q(t, t, p);
fmpz_add(s, s, t);
}
while (!fmpz_is_zero(t));
fmpz_swap(rop, s);
fmpz_clear(s);
fmpz_clear(t);
}