本文へスキップ
製品デスクトップツール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
ディスカッション

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

Practice problems

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

These problems were written to exercise each tool from the earlier chapters in turn. Try to work out an approach on your own before reading the solution.

Problem 1. Floor tiles

A rectangular floor measures W by H centimeters (integers). You want to cover it with identical square tiles, leaving no gaps and cutting no tiles. Find the side of the largest possible tile and how many tiles you need. Example: W = 120, H = 84 gives side 12 and 70 tiles.

Approach: the tile side must divide both W and H, so it is a common divisor, and the largest one is the GCD. The tile count is (W / g) × (H / g).

import math

def largest_tile(w: int, h: int) -> tuple[int, int]:
    g = math.gcd(w, h)
    return g, (w // g) * (h // g)

print(largest_tile(120, 84))  # (12, 70)
print(largest_tile(7, 5))     # (1, 35)

Problem 2. Blinking signals

There are k signal lights, and light i blinks once every p_i seconds. All of them blinked together at time 0. How many moments from second 1 to second T (inclusive) have every light blinking at once? Each p_i is at most 10^9, k is at most 10^5, and T is at most 10^18.

Approach: the lights all blink together exactly at common multiples of every period, so the answer is T // lcm(p_1, …, p_k). Fold the LCM with lcm(a, b) = a // gcd(a, b) * b. As soon as the LCM exceeds T the answer is 0, so stop early. That early exit also makes the code easy to port to C++ or Java without overflow.

import math

def simultaneous_blinks(periods: list[int], t: int) -> int:
    l = 1
    for p in periods:
        l = l // math.gcd(l, p) * p
        if l > t:
            return 0
    return t // l

print(simultaneous_blinks([4, 6, 10], 300))   # 5 (60, 120, 180, 240, 300)
print(simultaneous_blinks([7, 11, 13], 1000)) # 0 (lcm = 1001)

Problem 3. Prime counts in ranges

You get Q queries, each a pair L R with 1 ≤ L ≤ R ≤ 10^6. For each, print how many primes lie between L and R inclusive. Q can be as large as 10^5.

Approach: testing primality per query is too slow. Sieve once up to 10^6, build the prefix sum prefix[x] = number of primes ≤ x, and answer each query in O(1) as prefix[R] - prefix[L - 1].

def build_prime_prefix(limit: int) -> list[int]:
    is_prime = bytearray([1]) * (limit + 1)
    is_prime[0] = is_prime[1] = 0
    i = 2
    while i * i <= limit:
        if is_prime[i]:
            is_prime[i * i :: i] = bytes((limit - i * i) // i + 1)
        i += 1
    prefix = [0] * (limit + 1)
    running = 0
    for x in range(limit + 1):
        running += is_prime[x]
        prefix[x] = running
    return prefix

prefix = build_prime_prefix(10**6)
for left, right in [(1, 10), (10, 30), (1, 10**6)]:
    print(prefix[right] - prefix[left - 1])  # 4, 6, 78498
この章について質問がありますか?
前の章Complexity次の章Real-world use

Problem 4. Counting grid paths

On an R × C grid, count the paths from the top-left corner to the bottom-right corner that move only right or down, one unit at a time, modulo 10^9 + 7. There are up to 10^5 queries, with R + C ≤ 2 × 10^5.

Approach: every path makes R + C moves, R of them downward, so the answer is C(R + C, R). Precompute factorials and inverse factorials up to the maximum and each query costs two multiplications.

MOD = 10**9 + 7
LIMIT = 2 * 10**5

fact = [1] * (LIMIT + 1)
for i in range(1, LIMIT + 1):
    fact[i] = fact[i - 1] * i % MOD
inv_fact = [1] * (LIMIT + 1)
inv_fact[LIMIT] = pow(fact[LIMIT], MOD - 2, MOD)
for i in range(LIMIT, 0, -1):
    inv_fact[i - 1] = inv_fact[i] * i % MOD

def ncr(n: int, r: int) -> int:
    if r < 0 or r > n:
        return 0
    return fact[n] * inv_fact[r] % MOD * inv_fact[n - r] % MOD

print(ncr(2 + 2, 2))           # 6
print(ncr(3 + 7, 3))           # 120
print(ncr(100000 + 100000, 100000))  # 879467333

Problem 5. Solving a linear congruence

Given integers a, b and m (m ≥ 1), find every x with 0 ≤ x < m such that a × x ≡ b (mod m). Return an empty list if there is none.

Approach: with g = gcd(a, m), the equation a × x - m × y = b has integer solutions exactly when g divides b. If it does, divide through by g to get (a/g) × x ≡ (b/g) (mod m/g). Now a/g and m/g are coprime, so an inverse yields one solution x0, and the full set is x0 + k × (m/g) for k = 0 … g-1.

def gcd_with_coeff(a: int, b: int) -> tuple[int, int]:
    """Return (g, x) with a * x ≡ g (mod b), where g = gcd(a, b)."""
    old_r, r, old_x, x = a, b, 1, 0
    while r:
        q = old_r // r
        old_r, r = r, old_r - q * r
        old_x, x = x, old_x - q * x
    return old_r, old_x

def solve_linear_congruence(a: int, b: int, m: int) -> list[int]:
    a, b = a % m, b % m
    g, x = gcd_with_coeff(a, m)
    if b % g != 0:
        return []
    step = m // g
    x0 = (x * (b // g)) % step
    return [x0 + k * step for k in range(g)]

print(solve_linear_congruence(14, 30, 100))  # [45, 95]
print(solve_linear_congruence(4, 3, 6))      # [] — gcd 2 does not divide 3
print(solve_linear_congruence(3, 1, 7))      # [5] — the inverse of 3

The y coefficient is not needed here, so the extended Euclid loop tracks only x. Since a × x ≡ g (mod m), multiplying by b / g gives a × x ≡ b. Reducing modulo step at the end yields the smallest solution.

Summary

Reach for the GCD when something must be split into equal parts, the LCM when cycles must line up, a sieve plus prefix sums for repeated prime queries over a range, factorial tables for repeated binomial coefficients, and extended Euclid for inverses and congruences. A good habit: first decide which tool the problem needs, then check the input limits for overflow and time.

コメント 0件

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

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