Zum Hauptinhalt springen
ProdukteDesktop-WerkzeugeTASTECADZeichnungsprüfungTASTEFILESDateiverwaltungTASTEFTPDateiübertragungTASTESSHRemote-ArbeitsbereichTASTEZIPKomprimieren und EntpackenTASTEWINMDateiverwaltungEntwicklerwerkzeugeTASTECODEIntegrierte Entwicklungsumgebung für RustTASTESTUDIOIntegrierte Entwicklungs- und TestumgebungTASTEETLDatenintegration (ETL)ServerTASTEREMOTERemote-Desktop-ServerTASTEGEOGeodatenserverTASTEMAILE-Mail-ArbeitsbereichInvestierenTASTESTOCKDesktop-App für automatischen AktienhandelErste SchritteDownloadsDokumentationKaufenAlle Produkte
Marktplatz
Neuigkeiten
TechnikNeuigkeitenEntwickler-News von heuteEntwicklerdokuProgrammiersprachenRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp- & Desktop-FrameworksTauriFlutterReact NativeElectronAlgorithmenAlgorithmus-GrundlagenKernalgorithmenFortgeschrittene AlgorithmenAlgorithmen für die Praxis
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcaseCommunity-Leitfaden
ZusammenarbeitWissenstransferWebsite-AufbauDesktop-App-AufbauRelease- und ZahlungspipelineVertriebspartnerKontakt
DiensteRemote-DesktopIndividuelle Installationspakete
TASTEDEV
Produkte

Desktop-Werkzeuge

TASTECADKomplexe Zeichnungen, mühelos geöffnetTASTEFILESNur die Dateien, die zählen – in BestzeitTASTEFTPDer aufgeräumteste Weg für Ihre DateienTASTESSHDie stärkere Verbindung zu Ihren ServernTASTEZIPSchneller packen, sicherer entpackenTASTEWINMEin tastaturorientierter Dateimanager mit zwei Fenstern

Entwicklerwerkzeuge

TASTECODERust-Apps bearbeiten, bauen, debuggen und testen – alles in einem FensterTASTESTUDIOVom Bearbeiten bis zu Remote-Tests und freigegebenen KI-KorrekturenTASTEETLDaten bewegen, die Werte im Blick

Server

TASTEREMOTEEin Remote-Desktop auf Ihrem eigenen ServerTASTEGEOEin GeoServer-kompatibler Geodatenserver, neu aufgebaut in RustTASTEMAILIhre E-Mail wieder in Ihrer Hand

Investieren

TASTESTOCKAutomatischer Aktienhandel nach Ihren Regeln: wann und was

Erste Schritte

DownloadsNeueste Versionen aller ProdukteDokuSo nutzen Sie jedes ProduktKaufenAbos und DauerlizenzenAlle ProdukteAlle Produkte im Überblick
Alle Produkte
MarktplatzNeuigkeiten
Technik

Neuigkeiten

Entwickler-News von heuteOffizielle Meldungen zu Sprachen, Frameworks, GitHub und KIEntwicklerdokuAnleitungen zu Sprachen, Frameworks und Algorithmen

Programmiersprachen

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App- & Desktop-FrameworksTauriFlutterReact NativeElectron

Algorithmen

Algorithmus-GrundlagenKomplexitätsanalyse · Sortieren · Suchen · Grundlegende Datenstrukturen · Bäume und HeapsKernalgorithmenGraphtraversierung · Kürzeste Wege und minimale Spannbäume · Dynamische Programmierung · Greedy-Algorithmen · Teile und herrsche · BacktrackingFortgeschrittene AlgorithmenZeichenkettenalgorithmen · Mathematik und Zahlentheorie · Bitmanipulation · Segmentbäume · Union-FindAlgorithmen für die PraxisStrategie für Coding-Interviews · LRU-Cache · Rate Limiting · Konsistentes Hashing
Alle Entwicklungsdokumente
Community
ProjekteEntwickler und Projekte entdeckenEntwicklungslogsEntscheidungen und ErkenntnissePromptsWiederverwendbare AnweisungenProbleme mit KI-ToolsProbleme und Workarounds für Claude, Codex, GeminiShowcaseFertige ErgebnisseCommunity-LeitfadenWie wir offen entwickeln
Zusammenarbeit
WissenstransferNative Apps mit Rust und eguiWebsite-Aufbau10 Sprachen, Konten, Dokumentation und DownloadsDesktop-App-AufbauRust und egui, ohne WebViewRelease- und ZahlungspipelineSignatur, MSI, deb, rpm, AppImage, PrüfsummenVertriebspartnerEmpfehlen und 30 % erhaltenKontaktEntwicklung, Partnerschaft, Investition
Dienste
Remote-DesktopIhren Computer im Browser erreichenIndividuelle InstallationspaketeNur nötige Funktionen, Einstellungen vorab
Kaufen
DE
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Anmelden
Anmelden
TASTEDEV

Von kleinen Werkzeugen zu besserer Entwicklung.

support@tastedev.netTASTEDEV unterstützen
ProdukteProduktübersichtKaufenDokuDownloadsMarktplatzSupport
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcase
RichtlinienÜber unsDatenschutzerklärungNutzungsbedingungenAbo-BedingungenRückerstattungCommunity-Richtlinien
KontoAnmeldenRegistrieren
Besucher
Heute
Gestern
Aufrufe gesamt
Firma
GXSOFT
Vertretungsberechtigt
CHOI YOUNG GU
Handelsregisternummer
853-44-00368
Anschrift
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefon
+82-10-4404-1523
E-Mail
whitecalvin@tastedev.net
Datenschutzbeauftragter
CHOI YOUNG GU

© 2026 TASTEDEVProduktinformationen basieren auf verifizierten Entwicklungsquellen.Veröffentlicht · wird verbessert

Mathematik und Zahlentheorie-Dokumentation
Mathematik und Zahlentheorie
ConceptsHow it worksImplementationComplexityPractice problemsReal-world use
Diskussionen

Mathematik und Zahlentheorie-Anleitung · 2/6

How it works

Dieses Kapitel ist vorerst nur auf Englisch verfügbar.

This chapter traces each algorithm on small numbers. Following the tables by hand is the fastest way to see why the code looks the way it does.

Euclidean algorithm: gcd(252, 105)

Let r be the remainder of a divided by b. Because r = a - q × b, every common divisor of a and b also divides r, and vice versa. So replacing (a, b) with (b, r) keeps the GCD unchanged while the numbers keep shrinking.

Stepaba mod b
125210542
21054221
342210

The remainder hits 0 at step 3, so the answer is the b of that row: 21. Three steps in total.

def gcd(a: int, b: int) -> int:
    while b:
        a, b = b, a % b
    return a

print(gcd(252, 105))  # 21

Extended Euclid: 240x + 46y = gcd(240, 46)

The extended version tracks, next to each remainder r, the coefficients x and y that express it as 240 × x + 46 × y. Every time a quotient q is produced, all three values follow the same rule: new = previous - q × current.

qrxy
-24010
-4601
5101-5
46-421
145-26
12-947
2023-120

The answer is the row just before the remainder becomes 0: gcd = 2, x = -9, y = 47, and indeed 240 × (-9) + 46 × 47 = -2160 + 2162 = 2. Check that 240 × x + 46 × y = r holds on every row. That invariant is exactly why the algorithm is correct.

def extended_gcd(a: int, b: int) -> tuple[int, int, int]:
    old_r, r = a, b
    old_x, x = 1, 0
    old_y, y = 0, 1
    while r:
        q = old_r // r
        old_r, r = r, old_r - q * r
        old_x, x = x, old_x - q * x
        old_y, y = y, old_y - q * y
    return old_r, old_x, old_y

print(extended_gcd(240, 46))  # (2, -9, 47)
Fragen zu diesem Kapitel?
Vorheriges KapitelConceptsNächstes KapitelImplementation

Fast exponentiation: 3^13 mod 7

Instead of twelve multiplications, look at the exponent in binary. 13 = 1101 (base 2) = 8 + 4 + 1, so 3^13 = 3^8 × 3^4 × 3^1. Keep squaring the base (3, 3^2, 3^4, 3^8, …) and multiply it into the result only where the exponent has a 1 bit.

exp (binary)lowest bitresultbase (for next step)
110111 × 3 = 33^2 = 9 ≡ 2
110032^2 = 4
1113 × 4 = 12 ≡ 54^2 = 16 ≡ 2
115 × 2 = 10 ≡ 32^2 = 4

The answer is 3. Fermat's little theorem confirms it: 3^6 ≡ 1 (mod 7), so 3^13 = (3^6)^2 × 3 ≡ 3. The number of multiplications is proportional to the number of bits in the exponent, so even an exponent of 10^18 needs only about 60 iterations.

Sieve of Eratosthenes: primes up to 30

Walk upward from 2. Whenever you meet a number that has not been crossed out, it is prime, and you cross out all of its multiples. It is enough to start at i × i: any smaller multiple i × k with k < i was already crossed out while processing the smaller factor k.

inewly crossed out
24, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
39, 15, 21, 27 (12, 18, 24 and 30 are already gone)
4already crossed out, skip
525 (30 is already gone)
66 × 6 = 36 exceeds 30, stop

What remains is 2, 3, 5, 7, 11, 13, 17, 19, 23, 29: ten primes. The outer loop only runs while i × i ≤ n, so for 30 the work is effectively done at i = 5.

Factorization and nCr mod p

The simplest factorization method is trial division up to √n. For 360, divide by 2 three times (360, 180, 90, 45), then by 3 twice (45, 15, 5). The leftover 5 has no divisor up to √5, so it is prime, and 360 = 2^3 × 3^2 × 5.

A binomial coefficient C(n, r) = n! / (r! × (n - r)!) modulo a prime p cannot be computed by plain division. Instead you multiply by the inverse of the denominator. Inverting with Fermat's little theorem gives C(n, r) ≡ n! × (r!)^(p-2) × ((n-r)!)^(p-2) (mod p) when n < p.

p = 10**9 + 7

def ncr_mod(n: int, r: int) -> int:
    if r < 0 or r > n:
        return 0
    num = den = 1
    for i in range(r):
        num = num * (n - i) % p
        den = den * (i + 1) % p
    return num * pow(den, p - 2, p) % p

print(ncr_mod(10, 3))          # 120
print(ncr_mod(100000, 50000))  # 149033233 — the exact value has over 30,000 digits

Summary

The Euclidean algorithm shrinks big numbers by replacing them with remainders, and the extended version carries the Bezout coefficients along. Fast exponentiation uses the binary form of the exponent to cut the number of multiplications to a logarithm. The sieve crosses out multiples starting at i × i to find every prime in a range at once, and nCr mod p multiplies by inverses instead of dividing. The next chapter turns all of this into reusable code.

0 Kommentare

Top-KommentareNeueste zuerst

Anmelden · Melde dich an, um einen Kommentar zu schreiben.