PROGLIB_ACADEMY Telegram 2727
📈 Быстрое возведение числа в целую степень: алгоритм для новичков

Как компьютеры возводят числа в степень эффективно

🔵 Базовый способ:
— Умножаем число само на себя n раз.
— Просто, но медленно: O(n) операций.

def pow_naive(x, n):
result = 1
for _ in range(n):
result *= x
return result


🔵 Быстрый способ: возведение в степень через деление пополам (алгоритм "быстрого возведения в степень"):
— Сокращаем количество операций до O(log n)!
— Идея:
▪️ Если степень чётная → делим пополам.
▪️ Если нечётная → уменьшаем на 1 и снова работаем.

def fast_pow(x, n):
result = 1
while n > 0:
if n % 2 == 1:
result *= x
x *= x
n //= 2
return result


🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/proglib_academy/2727
Create:
Last Update:

📈 Быстрое возведение числа в целую степень: алгоритм для новичков

Как компьютеры возводят числа в степень эффективно

🔵 Базовый способ:
— Умножаем число само на себя n раз.
— Просто, но медленно: O(n) операций.

def pow_naive(x, n):
result = 1
for _ in range(n):
result *= x
return result


🔵 Быстрый способ: возведение в степень через деление пополам (алгоритм "быстрого возведения в степень"):
— Сокращаем количество операций до O(log n)!
— Идея:
▪️ Если степень чётная → делим пополам.
▪️ Если нечётная → уменьшаем на 1 и снова работаем.

def fast_pow(x, n):
result = 1
while n > 0:
if n % 2 == 1:
result *= x
x *= x
n //= 2
return result


🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст

BY Proglib.academy | IT-курсы




Share with your friend now:
tgoop.com/proglib_academy/2727

View MORE
Open in Telegram


Telegram News

Date: |

Earlier, crypto enthusiasts had created a self-described “meme app” dubbed “gm” app wherein users would greet each other with “gm” or “good morning” messages. However, in September 2021, the gm app was down after a hacker reportedly gained access to the user data. During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content. It’s yet another bloodbath on Satoshi Street. As of press time, Bitcoin (BTC) and the broader cryptocurrency market have corrected another 10 percent amid a massive sell-off. Ethereum (EHT) is down a staggering 15 percent moving close to $1,000, down more than 42 percent on the weekly chart. Telegram iOS app: In the “Chats” tab, click the new message icon in the right upper corner. Select “New Channel.” bank east asia october 20 kowloon
from us


Telegram Proglib.academy | IT-курсы
FROM American