Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <signal.h>
- enum { COUNT = 4 };
- enum { SIMPL = 2 };
- volatile int cnt = 0;
- int sim = 0;
- void hand_SIGTERM(int sig) {
- _exit(0);
- }
- void hand_SIGINT(int sig) {
- signal(SIGINT, hand_SIGINT);
- if (++cnt == COUNT) {
- _exit(0);
- }
- printf("%d\n", sim);
- }
- int simpl_check(int val) {
- if (val < 0) {
- return 0;
- }
- for (unsigned long long i = SIMPL; i * i <= val; ++i) {
- if (!(val % i)) {
- return 0;
- }
- }
- return 1;
- }
- int main(int argc, char **argv) {
- long long low, high;
- scanf("%lld", &low);
- scanf("%lld", &high);
- printf("%d\n", getpid());
- signal(SIGTERM, hand_SIGTERM);
- signal(SIGINT, hand_SIGINT);
- for (unsigned long long i = low; i < high; ++i) {
- if (simpl_check(i)) {
- sim = i;
- }
- }
- printf("-1\n");
- _exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement