Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4. void quickmath();
  5. int main(){
  6. char *input = (char*)malloc(10000*sizeof(char));
  7. size_t capacity = 100000;
  8. size_t *incap = &capacity;
  9. int counter = 0;
  10. pthread_t threads[420];
  11.  
  12. while(1){
  13. getline(&input, incap, stdin);
  14. if(input[0] == 'e'){
  15. pthread_exit(NULL);
  16. }
  17. if(input[0] == 'p'){
  18.  
  19. char masiv[999998];
  20. for(int i=2; input[i] != '\0' ; i++){
  21. masiv[i-2] = input[i];
  22. }
  23. int num = atoi(masiv);
  24. pthread_create(&threads[counter], NULL, (void*)quickmath, &num);
  25. counter++;
  26. }
  27.  
  28.  
  29. }
  30.  
  31. return 0;
  32. }
  33.  
  34. void quickmath(int* lol){
  35. int counter = 0;
  36. int flag = 2;
  37. int num = *lol;
  38. for(int i = 0; i < num; i++){
  39. for(int j = 2; j < i; j++){
  40. if(i % j == 0){
  41. flag = 1;
  42. break;
  43. }else{
  44. flag = 0;
  45. }
  46. }
  47. if(flag == 0){
  48. counter++;
  49. }
  50. }
  51. printf("%d\n", counter);
  52. pthread_exit(NULL);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement