1.
def sum_of_divisors(n):
divisors = [i for i in range(2, n) if n % i == 0]
return sum(divisors)
target_numbers = []
for num in range(500000, 10**6):
r = sum_of_divisors(num)
if str(r)[-1] == '3':
target_numbers.append((num, r))
target_numbers.sort()
for num, r in target_numbers[:5]:
print(f"{num} {r}")
2.
import math
def convert_to_pentary(num):
"""Converts a number to its representation in the pentary (base 5) system"""
pentary = ''
while num > 0:
pentary = str(num % 5) + pentary
num //= 5
return pentary
def count_zeros(expression):
"""Counts the number of zeros in the pentary representation of the expression"""
return expression.count('0')
# Compute the expression 5^150 + 5^100 - x
a = 5 ** 150
b = 5 ** 100
max_zeros = 0
best_x = 0
for x in range(a + b + 1):
expression = convert_to_pentary(a + b - x)
zeros = count_zeros(expression)
if zeros > max_zeros:
max_zeros = zeros
best_x = x
print(best_x)
3.
from itertools import product
# Все возможные буквы в словах
letters = 'партия'
# Функция для проверки условий
def check_word(word):
# Проверяем, чтобы в слове было не более одной буквы "я"
if word.count('я') > 1:
return False
# Проверяем, чтобы буквы "т" не стояли рядом
if 'тт' in word:
return False
return True
# Генерируем все пятибуквенные слова
all_words = [''.join(x) for x in product(letters, repeat=5)]
# Находим последнее слово, которое удовлетворяет условиям
for i, word in enumerate(all_words):
if check_word(word):
last_word = word
last_index = i + 1
print(last_index)