From 1e8df9f2badea15a9943bca2103afe2e88cff81d Mon Sep 17 00:00:00 2001 From: Utkarsh Singh <108651614+UtkarshSingh1923@users.noreply.github.com> Date: Tue, 1 Jul 2025 23:17:18 +0530 Subject: [PATCH] Update binary-exp.md Distributive law of modulo over multiplication to handle overflow --- src/algebra/binary-exp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algebra/binary-exp.md b/src/algebra/binary-exp.md index 52dfd27a5..7a9938fe9 100644 --- a/src/algebra/binary-exp.md +++ b/src/algebra/binary-exp.md @@ -104,8 +104,8 @@ long long binpow(long long a, long long b, long long m) { long long res = 1; while (b > 0) { if (b & 1) - res = res * a % m; - a = a * a % m; + res = (res%m * a%m) % m; + a = (a%m * a%m) % m; b >>= 1; } return res; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy