## 2018年4月5日木曜日

### 数学 - Python - JavaScript - 数学の中の女王 - 数論へのプレリュード – 合同式 - 合同式を解く(1次の合同式、足し算、引き算、掛け算算、推移律)

1. $\begin{array}{}52x\equiv 22\left(mod59\right)\\ -7x\equiv 22\left(mod59\right)\\ -21x\equiv 66\left(mod59\right)\\ -21x\equiv 7\left(mod59\right)\\ 5x\equiv 18\left(mod59\right)\\ 25x\equiv 90\left(mod59\right)\\ 25x\equiv 31\left(mod59\right)\\ 25x\equiv -28\left(mod59\right)\\ x\equiv 39\left(mod59\right)\end{array}$

2. $\begin{array}{}38x\equiv 54\left(mod35\right)\\ 3x\equiv 19\left(nod35\right)\\ 3x\equiv -16\left(mod35\right)\\ 18x=-96\left(mod35\right)\\ 18x\equiv 9\left(mod35\right)\\ x\equiv 18\left(mod35\right)\end{array}$

3. $\begin{array}{}104x\equiv 200\left(mod100\right)\\ 4x\equiv 200\left(mod100\right)\\ 4x\equiv 0\left(mod100\right)\\ 12x\equiv 0\left(mod100\right)\\ x\equiv 25\left(mod100\right)\end{array}$

4. $\begin{array}{}94x\equiv 52\left(mod111\right)\\ -17x\equiv 52\left(mod111\right)\\ -119x\equiv 364\left(mod111\right)\\ -8x\equiv 31\left(mod111\right)\\ -48x\equiv 186\left(mod111\right)\\ -48x\equiv 75\left(mod111\right)\\ -48x\equiv -36\left(mod111\right)\\ -x\equiv -10\left(mod111\right)\\ x\equiv 10\left(mod111\right)\end{array}$

コード(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()


$./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();


x ≡ (mod )