def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True # Loop through all 3-digit numbers starting with '5' for num in range(500, 600): if str(num).startswith('5') and is_prime(num): print(num)