|
1 /* |
|
2 * Simple test driver for MPI library |
|
3 * |
|
4 * Test 7: Random and divisibility tests |
|
5 * |
|
6 * This Source Code Form is subject to the terms of the Mozilla Public |
|
7 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
9 |
|
10 #include <stdio.h> |
|
11 #include <stdlib.h> |
|
12 #include <string.h> |
|
13 #include <ctype.h> |
|
14 #include <limits.h> |
|
15 #include <time.h> |
|
16 |
|
17 #define MP_IOFUNC 1 |
|
18 #include "mpi.h" |
|
19 |
|
20 #include "mpprime.h" |
|
21 |
|
22 int main(int argc, char *argv[]) |
|
23 { |
|
24 mp_digit num; |
|
25 mp_int a, b; |
|
26 |
|
27 srand(time(NULL)); |
|
28 |
|
29 if(argc < 3) { |
|
30 fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]); |
|
31 return 1; |
|
32 } |
|
33 |
|
34 printf("Test 7: Random & divisibility tests\n\n"); |
|
35 |
|
36 mp_init(&a); |
|
37 mp_init(&b); |
|
38 |
|
39 mp_read_radix(&a, argv[1], 10); |
|
40 mp_read_radix(&b, argv[2], 10); |
|
41 |
|
42 printf("a = "); mp_print(&a, stdout); fputc('\n', stdout); |
|
43 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); |
|
44 |
|
45 if(mpp_divis(&a, &b) == MP_YES) |
|
46 printf("a is divisible by b\n"); |
|
47 else |
|
48 printf("a is not divisible by b\n"); |
|
49 |
|
50 if(mpp_divis(&b, &a) == MP_YES) |
|
51 printf("b is divisible by a\n"); |
|
52 else |
|
53 printf("b is not divisible by a\n"); |
|
54 |
|
55 printf("\nb = mpp_random()\n"); |
|
56 mpp_random(&b); |
|
57 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); |
|
58 mpp_random(&b); |
|
59 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); |
|
60 mpp_random(&b); |
|
61 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); |
|
62 |
|
63 printf("\nTesting a for divisibility by first 170 primes\n"); |
|
64 num = 170; |
|
65 if(mpp_divis_primes(&a, &num) == MP_YES) |
|
66 printf("It is divisible by at least one of them\n"); |
|
67 else |
|
68 printf("It is not divisible by any of them\n"); |
|
69 |
|
70 mp_clear(&b); |
|
71 mp_clear(&a); |
|
72 |
|
73 return 0; |
|
74 } |