本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

数学と整数論 ドキュメント
数学と整数論
ConceptsHow it worksImplementationComplexityPractice problemsReal-world use
ディスカッション

数学と整数論 ガイド · 1/6

Concepts

この章は現在、英語でのみ提供しています。

Number theory studies the properties of integers, above all division and remainders. It turns up in code more often than you might expect: finding when two cycles line up again, reporting a huge count "modulo 10^9 + 7", building a list of primes, or understanding how public-key cryptography such as RSA works. This chapter sets out the vocabulary and intuition used throughout the rest of the guide.

Divisibility and primes

If a divided by b leaves remainder 0, then b is a divisor of a and a is a multiple of b. An integer greater than 1 whose only divisors are 1 and itself is a prime; any other integer greater than 1 is composite. 2, 3, 5, 7 and 11 are prime, while 12 = 2 × 2 × 3 is composite.

The fundamental theorem of arithmetic says every integer greater than 1 can be written as a product of primes in exactly one way, ignoring order. That product is its prime factorization: for example, 360 = 2^3 × 3^2 × 5. Once you know the factorizations, the number of divisors, the GCD and the LCM all fall out of comparing exponents.

GCD and LCM

The greatest common divisor (GCD) is the largest number that divides both inputs; the least common multiple (LCM) is the smallest positive number both inputs divide. For positive a and b, gcd(a, b) × lcm(a, b) = a × b, so a fast GCD gives you the LCM for free.

The standard way to compute a GCD is the Euclidean algorithm. Its key identity is gcd(a, b) = gcd(b, a mod b); when the remainder reaches 0, the current divisor is the answer. The extended Euclidean algorithm additionally finds integers x and y (Bezout coefficients) with a × x + b × y = gcd(a, b). Those coefficients are the key to modular inverses.

import math

print(math.gcd(84, 36))   # 12
print(math.lcm(84, 36))   # 252 (Python 3.9+)
print(84 * 36 // math.gcd(84, 36))  # 252, the same value

Modular arithmetic

a mod m is the remainder when a is divided by m. If a and b leave the same remainder modulo m, we say they are congruent and write a ≡ b (mod m). A clock is the classic example: five hours after 10 o'clock is 3 o'clock, not 15, because 15 ≡ 3 (mod 12).

Modular arithmetic is useful because addition, subtraction and multiplication preserve remainders:

  • (a + b) mod m = ((a mod m) + (b mod m)) mod m
この章について質問がありますか?
次の章How it works
  • (a - b) mod m = ((a mod m) - (b mod m) + m) mod m
  • (a × b) mod m = ((a mod m) × (b mod m)) mod m
  • So however large the intermediate values would get, you can take the remainder after every step and keep the numbers small. Division does not work this way, though. To compute a / b modulo m you multiply by the modular inverse of b.

    MOD = 10**9 + 7
    
    a, b = 123456789, 987654321
    print((a * b) % MOD)                  # 259106859
    print(((a % MOD) * (b % MOD)) % MOD)  # same value
    print(-7 % 3)                         # 2 — Python always returns a non-negative remainder here

    Modular inverses and Fermat's little theorem

    An x with a × x ≡ 1 (mod m) is the modular inverse of a. It exists only when gcd(a, m) = 1, that is, when a and m are coprime. There are two common ways to find it:

    • Solve a × x + m × y = 1 with the extended Euclidean algorithm; x is the inverse. This works for any modulus.
    • If the modulus is a prime p, Fermat's little theorem gives a^(p-1) ≡ 1 (mod p), so a^(p-2) is the inverse. Compute it with fast exponentiation.

    This is why competitive programming loves 10^9 + 7 and 998244353. Both are prime, so every nonzero value has an inverse, and both sit near 2^30, so the product of two residues still fits in a 64-bit integer.

    p = 10**9 + 7
    inv3 = pow(3, p - 2, p)         # Fermat's little theorem
    print(3 * inv3 % p)             # 1
    print(pow(3, -1, p) == inv3)    # True — built in since Python 3.8

    Vocabulary

    TermMeaning
    Prime / compositeOnly divisors are 1 and itself / any other integer above 1
    GCD / LCMGreatest common divisor / least common multiple
    CoprimeTwo numbers with gcd(a, b) = 1
    CongruentSame remainder modulo m, a ≡ b (mod m)
    Modular inverseThe x with a × x ≡ 1 (mod m)
    Fast exponentiationSquare repeatedly over the binary digits of the exponent, O(log e) multiplications
    Sieve of EratosthenesFind every prime up to n by crossing out multiples of primes
    nCr mod pA binomial coefficient reduced modulo a prime p

    When to reach for number theory

    • The statement says "print the answer modulo 10^9 + 7"
    • Cycles, repetition, or events that must coincide (LCM)
    • Splitting into equal parts or reducing a ratio (GCD)
    • Many primality checks or prime counts over a range (sieve)
    • Counting problems whose exact answer is astronomically large (nCr mod p)

    Summary

    Number theory gives you five core tools: the Euclidean algorithm (GCD and LCM), the rules of modular arithmetic, modular inverses (extended Euclid or Fermat), fast exponentiation, and the sieve of Eratosthenes. The next chapter traces each of them step by step on small inputs.

    コメント 0件

    人気のコメント順新しい順

    ログイン · ログインするとコメントできます。