Data Structures & AlgorithmsHardCodeforces Div2 B · factorisation
Problem: What is the largest prime factor of 600851475143? Run the trial-division code.
Problem: What is the largest prime factor of 600851475143? Run the trial-division code.
n = 600851475143
f = 2
last = 1
while f * f <= n:
while n % f == 0:
last = f
n //= f
f += 1
if n > 1:
last = n
print(last)What is printed?- A. 1471
- B. 839
- C. 71
- D. 6857
Correct answer: D. 6857
600851475143 = 71 * 839 * 1471 * 6857, and the largest prime factor is 6857. The trial-division loop removes each factor and keeps the last one found.
More Coding Interview Problems questions
- Problem: How many integers in [1, 999] are divisible by 7 but not by 14? Run the code. python print(sum(1 for x in range(1, 1000) if x % 7…
- Problem: How many ordered pairs (i < j) of [1, 2, 3, 4, 6] have a[j] divisible by a[i]? Run the code. python a = [1, 2, 3, 4, 6]…
- Problem: What is the minimum number of operations to go from 1 to 10 when each operation is +1 or 2? Run the BFS. python from collections…
- Problem: How many binary strings of length 4 avoid the substring '11'? Run the code. python print(sum(1 for t in range(16) if '11' not in…
- Problem: What is the minimum number of insertions and deletions needed to turn 'abc' into 'adc'? (Only insertions and deletions are…
- Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code. python import os…