## 2018年4月6日金曜日

### 数学 - Python - JavaScript - 数学の中の女王 - 数論へのプレリュード – 合同式 - 連立合同式(対ごとに素、積、最小公倍数)

1. $\begin{array}{}N=4·5·7=140\\ {N}_{1}=35\\ {N}_{2}=28\\ {N}_{3}=20\end{array}$
$\begin{array}{}35{t}_{1}\equiv 1\left(mod4\right)\\ -{t}_{1}\equiv 1\left(mod4\right)\\ {t}_{1}=-1\end{array}$
$\begin{array}{}28{t}_{2}\equiv 1\left(mod5\right)\\ -2{t}_{2}\equiv 1\left(mod5\right)\\ {t}_{2}=2\end{array}$
$\begin{array}{}20{t}_{3}\equiv 1\left(mod7\right)\\ -{t}_{3}\equiv 1\left(mod7\right)\\ {t}_{3}=-1\end{array}$
$\begin{array}{}{x}_{0}=35·\left(-1\right)·2+28·2·1+20·\left(-1\right)·3\\ =-70+56-60\\ =-74\end{array}$

よって求める答えは、

$\begin{array}{}x\equiv -74\left(mod140\right)\\ x\equiv 66\left(mod140\right)\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3

from sympy import pprint
from sympy.ntheory.modular import crt

pprint(crt((4, 5, 7), (2, 1, 3)))


$./sample12.py (66, 140)$


HTML5

<pre id="output0"></pre>
<label for="k0">k = </label>
<input id="k0" type="number" step="1" value="10">

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

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


JavaScript

let pre0 = document.querySelector('#output0'),
btn0 = document.querySelector('#run0'),
btn1 = document.querySelector('#clear0'),
input_k = document.querySelector('#k0'),
inputs = [input_k],
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 output = () => {
let k0 = parseInt(input_k.value, 10);

p((66 + 140 * k0 - 2) % 4 === 0);
p((66 + 140 * k0  - 1) % 5 === 0);
p((66 + 140 * k0  - 3) % 7 === 0);

};

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