michael@0: /* michael@0: * Simple test driver for MPI library michael@0: * michael@0: * Test 7: Random and divisibility tests michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define MP_IOFUNC 1 michael@0: #include "mpi.h" michael@0: michael@0: #include "mpprime.h" michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: mp_digit num; michael@0: mp_int a, b; michael@0: michael@0: srand(time(NULL)); michael@0: michael@0: if(argc < 3) { michael@0: fprintf(stderr, "Usage: %s \n", argv[0]); michael@0: return 1; michael@0: } michael@0: michael@0: printf("Test 7: Random & divisibility tests\n\n"); michael@0: michael@0: mp_init(&a); michael@0: mp_init(&b); michael@0: michael@0: mp_read_radix(&a, argv[1], 10); michael@0: mp_read_radix(&b, argv[2], 10); michael@0: michael@0: printf("a = "); mp_print(&a, stdout); fputc('\n', stdout); michael@0: printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); michael@0: michael@0: if(mpp_divis(&a, &b) == MP_YES) michael@0: printf("a is divisible by b\n"); michael@0: else michael@0: printf("a is not divisible by b\n"); michael@0: michael@0: if(mpp_divis(&b, &a) == MP_YES) michael@0: printf("b is divisible by a\n"); michael@0: else michael@0: printf("b is not divisible by a\n"); michael@0: michael@0: printf("\nb = mpp_random()\n"); michael@0: mpp_random(&b); michael@0: printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); michael@0: mpp_random(&b); michael@0: printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); michael@0: mpp_random(&b); michael@0: printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); michael@0: michael@0: printf("\nTesting a for divisibility by first 170 primes\n"); michael@0: num = 170; michael@0: if(mpp_divis_primes(&a, &num) == MP_YES) michael@0: printf("It is divisible by at least one of them\n"); michael@0: else michael@0: printf("It is not divisible by any of them\n"); michael@0: michael@0: mp_clear(&b); michael@0: mp_clear(&a); michael@0: michael@0: return 0; michael@0: }