Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/wait.h>
- volatile sig_atomic_t sgnt = 0;
- volatile sig_atomic_t easy = 0;
- void
- sig_hndl(int sig)
- {
- if (sig == SIGINT) {
- sgnt++;
- if (sgnt >= 4) {
- exit(0);
- } else {
- printf("%d\n", easy);
- fflush(stdout);
- }
- } else if (sig == SIGTERM) {
- exit(0);
- }
- }
- int
- is_easy(int num)
- {
- if (num == 1) {
- return 0;
- }
- int i;
- for (i = 2; num % i && i * i < num; i++);
- if (num % i) {
- return 1;
- }
- return 0;
- }
- int
- main(void)
- {
- sigaction(SIGINT, &(struct sigaction) { .sa_handler = sig_hndl, .sa_flags = SA_RESTART }, NULL);
- sigaction(SIGTERM, &(struct sigaction) { .sa_handler = sig_hndl, .sa_flags = SA_RESTART }, NULL);
- int low, high;
- scanf("%d%d", &low, &high);
- printf("%d\n", getpid());
- int i;
- for (i = low; i < high; i++) {
- if (is_easy(i)) {
- easy = i;
- }
- }
- printf("-1\n");
- fflush(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement