Report
Report
ID 7794
Problem 1
In this problem it is required to implement Fast Exponentiation in 3
versions two of them are the given naive1 and naive2 methods and the
iteration method, then time should be compared between the methods
and find the overflow value for each method.
Sample Runs
According to the previous sample runs we can see that the most time
efficient method is the iterative method in which we used the fast
modular exponentiation algorithm, followed by the naive 2 method
then lastly the naive 1 method.
The iterative method overflows first before naive1 and naive2 when
using a large value of power.
Both the naive1 and naive2 methods overflow if we use very large
numbers.
Problem 2
In this problem it is required to find prime numbers up to any given
limit using sieve of Eratosthenes algorithm.
Sieve of Eratosthenes is a simple and ancient algorithm used to find the
prime numbers up to any given limit and it is one of the most efficient
Let us take an example when n = 50. So we need to print all prime
numbers smaller than or equal to 50.
We create a list of all numbers from 2 to 50.
Acco
rding to the algorithm we will mark all the numbers which are divisible
by 2 and are greater than or equal to the square of it.
Now
we move to our next unmarked number 3 and mark all the numbers
which are multiples of 3 and are greater than or equal to the square of
it.
We continue this process and our final table will look like below:
So the prime numbers are the unmarked ones: 2, 3, 5, 7, 11, 13, 17, 19,
23, 29, 31, 37, 41, 43, 47.
Pseudocode
1.find primes up to N
2.For all numbers a : from 2 to sqrt(n)
IF a is unmarked THEN
a is prime
For all multiples of a (a < n)
mark multiples of as composite
3.All unmarked nummbers are prime!
Sample Runs
In this sample run we set the limit to 100 and find the prime numbers
from 0 to 100.
Problem 3
Sample Runs
In the above sample run we factorize 700 to its prime factors which are
22557