You can test if a number P is a prime by checking to make sure P
Ask Expert

Be Prepared For The Toughest Questions

Practice Problems

You can test if a number P is a prime by checking to make sure P

2. Testing for Prime Numbers

You can test if a number P is a prime by checking to make sure P % n (n is an integer) is not zero for lots of values 1 < n < P. Write a program to input a number (or generate a number randomly) and test it against k random values. Pick a bunch of known composite numbers and see how accurately your program rejects them. See if the results improve for larger values of k. Try k = 10, 100, 1000 and 10,000. You can easily try the program against large composite numbers by including:

i. Even numbers

ii. Numbers whose final digit is a 5

iii. Numbers where the sum of the digits is divisible by 3.

iv. Number constructed as the product of two positive integers.

v. Randomly generated numbers X that are then adjusted as follows:

X = X - X%K <-- X will now be divisible by K.

Hint
Mathematics"Trial division and Sieve of Eratosthenes are approaches used in testing very small primes. These methods possess certainty for small numbers but consume much time before attaining the thirty digit mark. If primes are meant for industrial purposes, the need of proving that they are prime remains unnecessary."...

Know the process

Students succeed in their courses by connecting and communicating with
an expert until they receive help on their questions

1
img

Submit Question

Post project within your desired price and deadline.

2
img

Tutor Is Assigned

A quality expert with the ability to solve your project will be assigned.

3
img

Receive Help

Check order history for updates. An email as a notification will be sent.

img
Unable to find what you’re looking for?

Consult our trusted tutors.

Developed by Versioning Solutions.