Data Structures & AlgorithmsModerateTCS NQT · number theory
Problem: What is the product of the distinct prime factors of 360? Run the code.
Problem: What is the product of the distinct prime factors of 360? Run the code.
n = 360
p, prod = 2, 1
while p * p <= n:
if n % p == 0:
prod *= p
while n % p == 0:
n //= p
p += 1
if n > 1:
prod *= n
print(prod)What is printed?- A. 60
- B. 360
- C. 30
- D. 15
Correct answer: C. 30
The distinct primes of 360 = 2^3 * 3^2 * 5 are 2, 3 and 5, whose product is 30. Multiplying the full prime powers gives 360.
More Coding Interview Problems questions
- Problem: What is the sum of all primes up to 50? Run the code. python print(sum(p for p in range(2, 51) if all(p % d for d in range(2…
- Problem: What is C(20, 10) mod 1000? Compute it with Pascal's triangle reduced mod 1000. Run the code. python n, k = 20, 10 C = [[0] (k +…
- Problem: How many distinct palindromes can be formed by rearranging the letters of 'aabb' (distinct strings, all letters used)? Run the…
- Problem: What is the minimum number of deletions to make the string 'abcca' a palindrome? Use the palindromic-subsequence DP and print…
- Problem: Find the next lexicographic permutation of the digits '1243' (the smallest permutation strictly greater than it). Run the code…
- Problem: Find the length of the longest substring of 'AABABBA' that can be made all one letter after at most k = 1 replacement. Run the…