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
# Задача 1. Последние цифры (100 баллов) | |
# ограничение по времени на тест: 1 секунда | |
# ограничение по памяти на тест: 256 мегабайт | |
# ввод / вывод: стандартный | |
# В каждом целом числе от M до N включительно | |
# берётся последняя (младшая) цифра, | |
# и все такие цифры складываются. | |
# Найдите получившуюся сумму. | |
def last_digit_sum(m, n): |
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 is_prime(n): | |
if n < 2: | |
return False | |
for i in range(2, int(n**0.5) + 1): | |
if n % i == 0: | |
return False |
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
# Here's a simple Python program that prints the first n numbers | |
# each of them is a product of 1 distinct primes: | |
# This program uses a simple algorithm to generate | |
# prime numbers up to a certain limit (n), and then prints the | |
# first n prime numbers. | |
def get_primes(n): | |
primes = [] | |
candidate = 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
# Как вариант, вот алгоритм для поиска возрастающей | |
# подследовательности максимальной длины в списке: | |
# Здесь используется динамическое программирование. | |
# Массив dp хранит длины возрастающих подследовательностей, | |
# заканчивающихся на текущем элементе. | |
# Для каждой пары элементов numbers[i] и numbers[j] сравнивается, | |
# является ли numbers[j] предшественником numbers[i] | |
# в возрастающей подследовательности. Если numbers[j] < numbers[i], | |
# то dp[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
# This game generates a random problem in the form of an | |
# equation like x + 5 = 12 and asks the user to solve for | |
# the variable. The user inputs their answer and the game | |
# checks if it's correct, printing a message accordingly. | |
import random | |
def generate_problem(): | |
operations = ['+', '-', '*', '/'] | |
operation = random.choice(operations) |
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
# This game generates a random mathematical quiz, | |
# asks the user to solve it, and checks if the answer | |
# is correct. The user has unlimited attempts to solve | |
# the quiz. If the answer is correct, the user passes | |
# the quiz, otherwise the user fails. | |
import random | |
def generate_quiz(): | |
# generate two random numbers |
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
# Последовательность A349597 задаётся по следующему правилу: | |
# a(n) is the sum of digits of a(n-1)! with a(1) = 3. | |
import sys | |
def factorial(n): | |
result = 1 | |
for i in range(2, n + 1): | |
result *= 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
# Here's a simple program that prints the product | |
# of the digits of M^N for all M and N in the given range: | |
# Here's an updated version of the program | |
# that sorts the results in ascending order: | |
def product_of_digits(n): | |
result = 1 | |
while n > 0: | |
result *= n % 10 |
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
# Here's a simple program that prints the product | |
# of the digits of M^N for all M and N in the given range: | |
def product_of_digits(n): | |
result = 1 | |
while n > 0: | |
result *= n % 10 | |
n //= 10 | |
return result | |
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 5 distinct primes... | |
from sympy import primerange | |
def find_5_primes_product(limit): | |
primes = list(primerange(2, limit)) | |
products = [] | |
for i in range(len(primes) - 4): | |
for j in range(i+1, len(primes) - 3): |
NewerOlder