A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Click to reveal answer
intermediate
Why do we only check divisors up to the square root of a number when testing for primality?
Because if a number has a divisor larger than its square root, it must also have a smaller divisor below the square root. So checking up to the square root is enough to find any divisor.
Click to reveal answer
beginner
What is the simplest method to check if a number is prime?
Try dividing the number by all integers from 2 up to the number minus one. If none divide evenly, the number is prime.
Click to reveal answer
beginner
What should you return if the number is less than 2 when checking for primality?
Return False because numbers less than 2 are not prime by definition.
Click to reveal answer
advanced
How can you improve the efficiency of prime checking beyond checking all numbers up to sqrt(n)?
You can skip even numbers after checking 2, or use advanced methods like the Sieve of Eratosthenes or probabilistic tests for large numbers.
Click to reveal answer
Which number is NOT a prime number?
A2
B3
C4
D5
✗ Incorrect
4 is not prime because it can be divided evenly by 2.
When checking if a number n is prime, up to which number should you check for divisors?
ASquare root of n
Bn/2
Cn+1
Dn-1
✗ Incorrect
Checking up to the square root of n is enough to find any divisor.
What should the function return for input 1 when checking primality?
AFalse
BError
CTrue
DNone
✗ Incorrect
1 is not a prime number, so the function should return False.
Which of these is a quick way to skip unnecessary checks when testing primality?
ACheck only even numbers
BCheck only odd numbers after 2
CCheck all numbers up to n
DCheck only multiples of 3
✗ Incorrect
After checking 2, you can skip even numbers because they are not prime.
What is the smallest prime number?
A3
B1
C0
D2
✗ Incorrect
2 is the smallest prime number.
Explain how to check if a number is prime using a simple loop.
Think about dividing the number by smaller numbers to find factors.
You got /4 concepts.
Why is it unnecessary to check divisors beyond the square root of a number when testing primality?
Consider how multiplication pairs work.
You got /3 concepts.
Practice
(1/5)
1. What does it mean for a number to be prime?
easy
A. It has exactly two distinct positive divisors: 1 and itself.
B. It is divisible by 2 only.
C. It is an even number greater than 2.
D. It has more than two divisors.
Solution
Step 1: Understand the definition of prime number
A prime number is a number greater than 1 that has no divisors other than 1 and itself.
Step 2: Compare options with definition
Only It has exactly two distinct positive divisors: 1 and itself. correctly states this definition.
Final Answer:
It has exactly two distinct positive divisors: 1 and itself. -> Option A
Quick Check:
Prime number = two divisors [OK]
Hint: Prime means only divisible by 1 and itself [OK]
Common Mistakes:
Thinking even numbers are always prime
Confusing prime with odd numbers
Believing prime numbers have multiple divisors
2. Which of the following Python code snippets correctly checks if a number n is prime?
easy
A. for i in range(2, n): if n % i != 0: return False; return True
B. for i in range(1, n): if n % i == 0: return False; return True
C. for i in range(2, n): if n % i == 0: return False; return True
D. for i in range(2, n): if n % i == 1: return False; return True
Solution
Step 1: Analyze the loop range and condition
for i in range(2, n): if n % i == 0: return False; return True checks divisibility from 2 to n-1, which is correct for prime checking.
Step 2: Check the condition for returning False
If any divisor divides n evenly (remainder 0), return False; else True after loop ends.
Final Answer:
for i in range(2, n): if n % i == 0: return False; return True -> Option C
Quick Check:
Check divisors from 2 to n-1 for remainder 0 [OK]
Hint: Check divisors from 2 to n-1 for zero remainder [OK]
Common Mistakes:
Starting loop from 1 instead of 2
Checking for remainder not equal to zero
Checking if remainder equals 1 instead of 0
3. What is the output of the following code when n = 11?
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
print(is_prime(11))
medium
A. True
B. False
C. None
D. Error
Solution
Step 1: Check if n is less than or equal to 1
Since 11 > 1, skip the first return False.
Step 2: Loop from 2 to sqrt(11) + 1 (which is 4)
Check divisibility by 2 and 3; 11 % 2 != 0 and 11 % 3 != 0, so loop ends without returning False.
Step 3: Return True after loop
No divisor found, so function returns True.
Final Answer:
True -> Option A
Quick Check:
11 is prime, so output is True [OK]
Hint: Check divisors up to sqrt(n) for efficiency [OK]
Common Mistakes:
Looping up to n instead of sqrt(n)
Returning False too early
Not handling n <= 1 case
4. Find the error in this prime checking function and select the correct fix:
def is_prime(n):
if n < 2:
return False
for i in range(2, n):
if n % i == 0:
return False
else:
return True
medium
A. Change range to start from 1 instead of 2
B. Change if condition to n % i != 0
C. Add return True inside the else block
D. Remove the else block inside the loop to return True after loop ends
Solution
Step 1: Identify the problem with else inside the loop
The else causes the function to return True on first non-divisor, which is incorrect.
Step 2: Fix by removing else and returning True after loop
Return True only after checking all divisors without finding any.
Final Answer:
Remove the else block inside the loop to return True after loop ends -> Option D
Quick Check:
Return True only after full divisor check [OK]
Hint: Return True after loop, not inside it [OK]
Common Mistakes:
Returning True too early inside loop
Starting loop from 1
Changing condition to wrong remainder check
5. You want to check if a large number n is prime efficiently. Which approach is best?
hard
A. Check divisibility from 2 to n-1
B. Check divisibility from 2 to sqrt(n)
C. Check divisibility only by 2 and 3
D. Check divisibility from 1 to n
Solution
Step 1: Understand the efficiency of divisor checking
Checking up to n-1 or n is slow for large n; checking only 2 and 3 misses other divisors.
Step 2: Use the mathematical fact that divisors come in pairs
If n has a divisor greater than sqrt(n), it must have a corresponding divisor less than sqrt(n).
Step 3: Check divisibility only up to sqrt(n)
This reduces the number of checks drastically and is the best approach.
Final Answer:
Check divisibility from 2 to sqrt(n) -> Option B
Quick Check:
Divisors up to sqrt(n) suffice for prime check [OK]
Hint: Check divisors only up to square root of n [OK]
Common Mistakes:
Checking all numbers up to n
Checking only 2 and 3
Starting divisor check from 1
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.