#include #include #include int target; int num_threads; void* find_factors(void* arg) { int start = *((int*)arg); for (int i = start; i <= target / 2; i = i + num_threads) { if (target % i == 0) { printf("%d is a factor\n", i); } } } int main(int argc, char** argv) { target = atoi(argv[1]); num_threads = 3; pthread_t threads[num_threads]; int starts[num_threads]; for (int i = 0; i < num_threads; i++) { starts[i] = i + 2; pthread_create(&threads[i], NULL, find_factors, &starts[i]); } for (int i = 0; i < num_threads; i++) pthread_join(threads[i], NULL); printf("All done!\n"); }