Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- void quickmath();
- int main(){
- char *input = (char*)malloc(10000*sizeof(char));
- size_t capacity = 100000;
- size_t *incap = &capacity;
- int counter = 0;
- pthread_t threads[420];
- while(1){
- getline(&input, incap, stdin);
- if(input[0] == 'e'){
- pthread_exit(NULL);
- }
- if(input[0] == 'p'){
- char masiv[999998];
- for(int i=2; input[i] != '\0' ; i++){
- masiv[i-2] = input[i];
- }
- int num = atoi(masiv);
- pthread_create(&threads[counter], NULL, (void*)quickmath, &num);
- counter++;
- }
- }
- return 0;
- }
- void quickmath(int* lol){
- int counter = 0;
- int flag = 2;
- int num = *lol;
- for(int i = 0; i < num; i++){
- for(int j = 2; j < i; j++){
- if(i % j == 0){
- flag = 1;
- break;
- }else{
- flag = 0;
- }
- }
- if(flag == 0){
- counter++;
- }
- }
- printf("%d\n", counter);
- pthread_exit(NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement