This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Please, write a Python program that prints the first 5 numbers | |
# each of them is a product of 4 distinct primes... | |
from sympy import primerange | |
def find_4_primes_product(limit): | |
primes = list(primerange(2, limit)) | |
products = [] | |
for i in range(len(primes) - 3): | |
for j in range(i+1, len(primes) - 2): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The code you provided calculates and prints | |
# the result of i! modulo 3*i - 5 for i in | |
# the range [2, 20). | |
def factorial(n): | |
if n == 0: | |
return 1 | |
return n * factorial(n-1) | |
def mod_factorial(n, m): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Эта программа получает на входе натуральное число | |
# и выдаёт представление этого числа в виде суммы | |
# чисел Люка, используя жадный алгоритм. | |
def lucas_sum(n): | |
if n == 0: | |
return 2 | |
elif n == 1: | |
return 1 | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Эта программа получает на вход натуральное число | |
# и выдает представление этого числа в виде суммы | |
# чисел Фибоначчи, используя жадный алгоритм. | |
def fibonacci_sum(n): | |
if n == 0: | |
return 0 | |
elif n == 1: | |
return 1 | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Когда Таня купалась в море, в её электронные часы попала вода. | |
# Теперь эти часы по-прежнему показывают правильное время, | |
# но разделитель (двоеточие между количеством часов | |
# и количеством минут) пропал. Например, вместо 23:40 | |
# Танины часы покажут 2340 (промежутком на месте пропавшего | |
# разделителя пренебречь). | |
# Итак, Таня посмотрела на свои уже испорченные часы | |
# и увидела там 4-значное число, в котором нет двух | |
# одинаковых цифр. Через некоторое время Таня снова посмотрела |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Клава поменяла местами две соседние цифры в числе 682479 | |
# и получила меньшее число. Какое? | |
number = 682479 | |
num_str = str(number) | |
for i in range(len(num_str)-1): | |
new_num_str = num_str[:i] + num_str[i+1] + num_str[i] + num_str[i+2:] | |
new_num = int(new_num_str) | |
if new_num < number: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# У натуральных чисел n и n+1 | |
# взяли по собственному делителю. | |
# Сумма этих двух собственных делителей оказалась равна 2023. | |
# Какое наименьшее значение могло иметь число n? | |
def proper_divisors(n): | |
divisors = [] | |
for i in range(1, n): | |
if n % i == 0: | |
divisors.append(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# У натуральных чисел n и n+1 | |
# взяли по собственному делителю. | |
# Сумма этих двух собственных делителей оказалась равна 2023. | |
# Какое наименьшее значение могло иметь число n? | |
for n in range (1, 2500): | |
for i in range(1, n): | |
if n % i == 0: | |
for j in range(1, n+1): | |
if (n+1) % j == 0 and i+j==2023: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Напиши программу на Питоне, которая определяет, | |
# что больше: sin (7.2 pi) или tan (7.25 pi)? | |
import math | |
a = math.sin(7.2 * math.pi) | |
b = math.tan(7.25 * math.pi) | |
if a > b: | |
print("sin(7.2 pi) is greater") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# В OEIS есть последовательность | |
# A162462 Sum of all numbers from n to sigma(n). | |
# Мне вот подумалось, а почему бы не создать последовательность | |
# «Sum of all numbers from τ(n) to n», | |
# они ведь так похожи, прямо сёстры-близняшки: | |
from sympy import divisors | |
def b(n): |