Alterna · учебный материал
Euclid, numbers and delimitation
36.3: Euclid, number and division numbers, short theory, one example, and Python step-by-step.
Что в этом материале
- How it works.
- One example in execution
- Remember
Содержание и основные понятия
The numerical algorithms are constructed from a small set of bricks: %, / /, the cycle and the neat edge of the overtaking.
substance and practice
Grade 8
OGE No. 6
OGE No. 16
EGE No. 25
01
How it works.
The numerical algorithms are built on a precise domain: which numbers are permissible, as defined by the answer for 0 and 1, where the over-seat ends.
Figures.
For non-negative n: n%10 takes the last digit, n / / / 10 removes it.
SPLM.
Euclid replaces (a, b) with (b, a % b) until b becomes 0.
The digger.
d is the divisor n if n% d = 0.
Square root.
If n is composite, it has a divisor no greater than sqrt(n).
02
One example in execution
Start the short program and go over the lines. The visualiser only shows the code, current line, variables and output.
To check the simplicity of the number
n
It's enough to look for a divider from 2 to
isqrt(n)
All of it.
math.isqrt
Returns an entire portion of the square root without float error. Numbers 0 and 1 are not simple; this should be clearly reflected before the cycle. The Euclid algorithm usually implies non-negative arguments, and the SPLM result sign is agreed not negative.
Algorithm map
Read from left to right, then run the code.
1
Start
2
a = 84, b = 30
3
Replace (a, b) with (b, a % b)
4
Save New Couple
5
Take out the pair.
03
Remember
Process n < 2 before divisor.
For the complete square, the isqrt(n) boundary shall be checked.
Check the DNA for equal numbers and the case where the second number is already zero.
Syntax of this page
from math import isqrt
Imports an entire square root from the standard math module.
isqrt(n)
Returns floor(sqrt(n)) for non-negative n.
range(2, isqrt(n) + 1)
It includes the entire boundary of the divisor checks.
%
Checks that there's no residue in the division.
while b: a, b = b, a % b
A composite form of the Euclid algorithm for the SPLM.
int(input())
Reads the whole number.
print
The answer or the logical mark comes out.