71 lines
1.7 KiB
C
Raw Permalink Normal View History

2018-10-18 12:04:07 +02:00
/*
2019-09-23 20:44:23 +02:00
* Copyright (C) 2019 Ortega Froysa, Nicolás <nicolas@ortegas.org>
* Author: Ortega Froysa, Nicolás <nicolas@ortegas.org>
2018-10-18 12:04:07 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2019-09-23 20:44:23 +02:00
#include "globals.h"
2019-09-24 08:20:09 +02:00
#include "llist.h"
#include "prime_test.h"
2019-09-23 20:44:23 +02:00
#include <signal.h>
2018-10-18 12:04:07 +02:00
#include <stdio.h>
2018-10-18 14:56:15 +02:00
#include <gmp.h>
2018-10-18 12:04:07 +02:00
2019-09-23 20:44:23 +02:00
int run = 1;
2018-10-18 12:04:07 +02:00
2019-09-23 20:44:23 +02:00
void quit_signal(int signum) {
printf("Received signal %d. Ending process...\n", signum);
run = 0;
}
2018-10-18 12:04:07 +02:00
2019-09-23 20:44:23 +02:00
int main() {
printf("%s v%s\n", APP_NAME, VERSION);
2018-10-18 14:56:15 +02:00
2019-09-23 20:44:23 +02:00
signal(SIGINT, quit_signal);
2018-10-18 14:56:15 +02:00
mpz_t test_base; // number used to get tested numbers
mpz_t p0, p1; // numbers to be tested for prime-ness.
2018-10-18 14:56:15 +02:00
mpz_inits(test_base, p0, p1, NULL);
2019-10-08 18:02:45 +02:00
mpz_set_ui(test_base, 6); // test_base = 6*k
2018-10-18 14:56:15 +02:00
2019-10-08 17:10:39 +02:00
puts("2");
puts("3");
2019-10-08 17:10:39 +02:00
2019-09-23 20:44:23 +02:00
while(run)
2018-10-18 14:56:15 +02:00
{
mpz_sub_ui(p0, test_base, 1); // p0 = test_base - 1
mpz_add_ui(p1, test_base, 1); // p0 = test_base + 1
if(test_prime(p0))
2018-10-18 14:56:15 +02:00
{
mpz_out_str(stdout, 10, p0);
printf("\n");
2018-10-18 14:56:15 +02:00
}
if(test_prime(p1))
2018-10-18 15:05:01 +02:00
{
mpz_out_str(stdout, 10, p1);
2019-09-23 20:44:23 +02:00
printf("\n");
2018-10-18 15:05:01 +02:00
}
2019-09-23 20:44:23 +02:00
2019-10-08 18:02:45 +02:00
mpz_add_ui(test_base, test_base, 6); // k += 1
2018-10-18 14:56:15 +02:00
}
mpz_clears(test_base, p0, p1, NULL);
2018-10-18 14:56:15 +02:00
2018-10-18 12:04:07 +02:00
return 0;
}