## 2017年12月26日火曜日

### 数学 - Python - JavaScript - 代数学 - 整数 - 同値関係、合同式(法と互いに素な公約数)

1. $ac-bc=\left(a-b\right)c$

問題の仮定より、

$m|a-b$

よって

$\begin{array}{}a-b\equiv 0\left(mod\left(m\right)\right)\\ a\equiv b\left(mod\left(m\right)\right)\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3
import random

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

m = 11
c = 13

for _ in range(10):
a = random.randrange(100)
b = random.randrange(100)
for t in [mod(a * c, b * c, m), mod(a, b, m)]:
print(t)
print()


$./sample2.py False False True True False False False False False False False False False False False False True True False False$


HTML5

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

<input id="a0" type="number" step="1" value="26">・
<input id="c0" type="number" step="1" value="11">
≡
<input id="b0" type="number" step="1" value="39">・
<span id="c1"></span>
(mod <input id="m0" type="number" step="1" value="13">)
<br>
<button id="run0">run</button>
<button id="clear0">clear</button>
<script src="sample2.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_c0 = document.querySelector('#c0'),
input_m0 = document.querySelector('#m0'),
span_c1 = document.querySelector('#c1'),
inputs = [input_a0, input_b0, input_c0, 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),
c0 = parseInt(input_c0.value, 10),
m0 = parseInt(input_m0.value, 10);

span_c1.textContent = c0;

p(a = ${a0}, b =${b0}, m = \${m0});
p((a0 * c0 - b0 * c0) % m0 == 0);
p((a0 - b0) % m0 == 0);
};

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


(mod )