edited by
365 views
1 votes
1 votes

The objective of this exercise is to implement a multithreaded solution to find if a given number is a perfect number. $N$ is a perfect number if the sum of all its factors, excluding itself, is $N;$ examples are $6$ and $28$. The input is an integer, $N$. The output is true if the number is a perfect number and false otherwise. The main program will read the numbers $N$ and $P$ from the command line. The main process will spawn a set of $P$ threads. The numbers from $1$ to $N$ will be partitioned among these threads so that two threads do not work on the name number. For each number in this set, the thread will determine if the number is a factor of $N$. If it is, it adds the number to a shared buffer that stores factors of $N$. The parent process waits till all the threads complete. Use the appropriate synchronization primitive here. The parent will then determine if the input number is perfect, that is, if $N$ is a sum of all its factors and then report accordingly. $($Note: You can make the computation faster by restricting the numbers searched from $1$ to the square root of $N.)$

edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
0 votes
0 votes
0 answers
4