## 2017年12月25日月曜日

### 数学 - Python - JavaScript - 代数学 - 整数 - 同値関係、合同式(法の整数倍を加えた場合)

1. $\begin{array}{}a-\left(b+mk\right)\\ =\left(a-b\right)-mk\\ =\mathrm{ml}-mk\\ =m\left(l-k\right)\end{array}$

よって、

$a\equiv b\left(mod\left(m\right)\right)⇒a\equiv b+mk\left(mod\left(m\right)\right)$

コード(Emacs)

Python 3

#!/usr/bin/env python3

def mod(a, b, m):
return (a - b) % m == 0

a = 11
b = 21
m = 2

for k in range(10):
print(f'{k}: {mod(a, b + k * m, m)}')


$./sample1.py 0: True 1: True 2: True 3: True 4: True 5: True 6: True 7: True 8: True 9: True$


HTML5

<pre id="output0"></pre>

<input id="a0" type="number" step="1" value="3">
≡
<input id="b0" type="number" step="1" value="5">
+
<input id="k0" type="number" step="1" value="10">・
<input id="m0" type="number" step="1" value="2">
(mod <span id="m1"></span>)
<br>
<button id="run0">run</button>
<button id="clear0">clear</button>
<script src="sample1.js"></script>


JavaScript

let pre0 = document.querySelector('#output0'),
run0 = document.querySelector('#run0'),
clear0 = document.querySelector('#clear0'),
input_a0 = document.querySelector('#a0'),
input_b0 = document.querySelector('#b0'),
input_k0 = document.querySelector('#k0'),
input_m0 = document.querySelector('#m0'),
span_m1 = document.querySelector('#m1'),
inputs = [input_a0, input_b0, input_k0, input_m0],
range = (n) => {
let result = [];

for (let i = 0; i < n; i += 1) {
result.push(i);
}

return result;
},
p = (text) => pre0.textContent += text + '\n',
clear = () => pre0.textContent = '',
output = () => {
let a0 = parseInt(input_a0.value, 10),
b0 = parseInt(input_b0.value, 10),
k0 = parseInt(input_k0.value, 10),
m0 = parseInt(input_m0.value, 10);

span_m1.textContent = m0;

p((a0 - (b0 + k0 * m0)) % m0 == 0);
};

run0.onclick = output;
clear0.onclick = clear;
inputs.forEach((input) => input.onchange = output);
output();


+

(mod )