File: MoreFacTest.cpp

package info (click to toggle)
ntl 11.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,760 kB
  • sloc: cpp: 91,320; sh: 10,577; ansic: 2,998; makefile: 535
file content (66 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download | duplicates (5)
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
#include <NTL/ZZXFactoring.h>

NTL_CLIENT

long NumFacs(const vec_pair_ZZX_long& v)
{
   long i;
   long res;

   res = 0;
   
   for (i = 0; i < v.length(); i++)
      res += v[i].b;

   return res;
}


int main()
{
   long cnt = 0;
   while (SkipWhiteSpace(cin)) {
      cnt++;
      cerr << ".";

      vec_ZZ w;
      ZZX f1, f;
      long nfacs;

      cin >> w;
      cin >> nfacs;

      long i, n;
      n = w.length();
      f.rep.SetLength(n);
      for (i = 0; i < n; i++)
         f.rep[i] = w[n-1-i];
      f.normalize();

      vec_pair_ZZX_long factors;
      ZZ c;

      factor(c, factors, f, 0);


      mul(f1, factors);
      mul(f1, f1, c);

      if (f != f1) {
         cerr << f << "\n";
         cerr << c << " " << factors << "\n";
         TerminalError("FACTORIZATION INCORRECT (1) !!!");
      }

      long nfacs1 = NumFacs(factors);

      if (nfacs1 != nfacs)
         TerminalError("FACTORIZATION INCORRECT (2) !!!");
   }


   cerr << "\n";
   cerr << "MoreFacTest OK\n";

   return 0;
}