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
/*
Copyright (C) 2009 William Hart
Copyright (C) 2024 Albin Ahlbäck
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 "test_helpers.h"
#include "ulong_extras.h"
TEST_FUNCTION_START(n_factor_ecm, state)
{
int i, j, k, result, fails;
ulong prime1, prime2, prod, f, mod;
fails = 0;
for (i = 10; i < FLINT_BITS; i += 5)
{
for (j = i; j < FLINT_BITS - i; j += 5)
{
for (k = 0; k < flint_test_multiplier(); k++)
{
prime1 = n_randprime(state, i, 1);
prime2 = n_randprime(state, j, 1);
prod = prime1 * prime2;
result = n_factor_ecm(&f, (i + j) << 2, 1000, 50000, state, prod);
if (result)
{
mod = prod % f;
if ((mod != 0) || (f == prod) || (f == 1))
TEST_FUNCTION_FAIL(
"Wrong answer from stage %d\n"
"Number: %wu = %wu * %wu\n"
"Factor found: %wu\n",
result, prod, prime1, prime2, f);
}
else
fails += 1;
}
}
}
if (fails > 2 * flint_test_multiplier())
TEST_FUNCTION_FAIL("Too many unsuccessful factorizations, %d\n", fails);
TEST_FUNCTION_END(state);
}