Loading [MathJax]/jax/output/HTML-CSS/jax.js

2018年4月5日木曜日

学習環境

数学読本〈6〉線形写像・1次変換/数論へのプレリュード/集合論へのプレリュード/εとδ/落ち穂拾い など(松坂 和夫(著)、岩波書店)の第23章(数学の中の女王 - 数論へのプレリュード)、23.2(合同式)、合同式を解く、問11.を取り組んでみる。



    1. 52x22(mod59)-7x22(mod59)-21x66(mod59)-21x7(mod59)5x18(mod59)25x90(mod59)25x31(mod59)25x-28(mod59)x39(mod59)

    2. 38x54(mod35)3x19(nod35)3x-16(mod35)18x=-96(mod35)18x9(mod35)x18(mod35)

    3. 104x200(mod100)4x200(mod100)4x0(mod100)12x0(mod100)x25(mod100)

    4. 94x52(mod111)-17x52(mod111)-119x364(mod111)-8x31(mod111)-48x186(mod111)-48x75(mod111)-48x-36(mod111)-x-10(mod111)x10(mod111)

コード(Emacs)

Python 3

#!/usr/bin/env python3

from sympy import pprint, symbols,  solve


def f(a, b, c):
    for x in range(1, c + 1):
        if (a * x - b) % c == 0:
            return x

ts = [(26, 11, 59),
      (19, 27, 35),
      (13, 25, 100),
      (47, 26, 111)]

for i, (a, b, c) in enumerate(ts, 1):
    for t in [i, f(a, b, c)]:
        print(t)
    print()

入出力結果(Terminal, Jupyter(IPython))

$ ./sample11.py
1
39

2
18

3
25

4
10

$

HTML5

<pre id="output0"></pre>
<input id="a0" type="number" step="1" value="26">x ≡ <input id="b0" type="number" min="0" step="1" value="11">(mod <input id="c0" type="number" step="1" value="59">)

<button id="run0">run</button>
<button id="clear0">clear</button>

<script src="sample11.js"></script>

JavaScript

let pre0 = document.querySelector('#output0'),
    btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    input_a0 = document.querySelector('#a0'),
    input_b0 = document.querySelector('#b0'),
    input_c0 = document.querySelector('#c0'),
    inputs = [input_a0, input_b0, input_c0],
    p = (x) => pre0.textContent += x + '\n',
    range = (start, end, step=1) => {
        let res = [];
        for (let i = start; i < end; i += step) {
            res.push(i);
        }
        return res;
    };

let f = (a, b, c) => {
    for (let x = 1; x <= c; x += 1) {
        if ((a * x - b) % c === 0) {
            return x;
        }
    }
};

let output = () => {
    let a0 = parseInt(input_a0.value, 10),
        b0 = parseInt(input_b0.value, 10),
        c0 = parseInt(input_c0.value, 10);

    p(f(a0, b0, c0));
};

inputs.forEach((input) => input.onchange = output);
btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';
output();
39
x ≡ (mod )

0 コメント:

コメントを投稿