Which of the following algorithms is used to efficiently compute the power of a number?
What is the time complexity of the Sieve of Eratosthenes algorithm for finding prime numbers up to a given limit?
Which of the following algorithms is used to find the greatest common divisor (GCD) of two numbers?
In linear diophantine equations of the form ax + by = c, where a, b, and c are integers, which of the following is true?
Which of the following is an example of a linear diophantine equation?
What will be the output of the code snippet?
a = 5
b = 3
c = a + b
print(c)
What will be the output of the code snippet?
a = 10
b = 2
c = a / b
print(c)
What will be the output of the code snippet?
a = 10
b = 3
c = a % b
print(c)
What will be the output of the following code snippet?
def binary_exponentiation(a, n):
if n == 0:
return 1
elif n % 2 == 0:
x = binary_exponentiation(a, n // 2)
return x * x
else:
x = binary_exponentiation(a, (n - 1) // 2)
return a * x * x
result = binary_exponentiation(2, 5)
print(result)
What will be the output of the following code snippet?
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
result = gcd(21, 14)
print(result)
What will be the output of the following code snippet?
def sieve_of_eratosthenes(n):
prime = [True] * (n + 1)
p = 2
while p * p <= n:
if prime[p] == True:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
primes = []
for p in range(2, n + 1):
if prime[p]:
primes.append(p)
return primes
result = sieve_of_eratosthenes(20)
print(result)
What will be the output of the following code snippet?
def linear_diophantine(a, b, c):
g = gcd(a, b)
if c % g != 0:
return "No solution exists."
x0, y0 = extended_euclidean(a, b)
x = x0 * (c // g)
y = y0 * (c // g)
return x, y
result = linear_diophantine(5, 7, 16)
print(result)
What will be the output of the following code snippet?
def binary_exponentiation(a, n):
if n == 0:
return 1
elif n % 2 == 0:
x = binary_exponentiation(a, n // 2)
return x * x % 1000000007
else:
x = binary_exponentiation(a, (n - 1) // 2)
return a * x * x % 1000000007
result = binary_exponentiation(2, 10)
print(result)
What will be the output of the following code snippet?
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
result = gcd(24, 36)
print(result)
What will be the output of the following code snippet?
def linear_diophantine(a, b, c):
g = gcd(a, b)
if c % g != 0:
return "No solution exists."
x0, y0 = extended_euclidean(a, b)
x = x0 * (c // g)
y = y0 * (c // g)
return x, y
result = linear_diophantine(3, 5, 8)
print(result)