Modulo without using%

[Procession Programmer](https://www.amazon.co.jp/%E8%A1%8C%E5%88%97%E3%83%97%E3%83%AD%E3%82%B0%E3% 83% A9% E3% 83% 9E% E3% 83% BC-% E2% 80% 95 Python% E3% 83% 97% E3% 83% AD% E3% 82% B0% E3% 83% A9% E3% 83 % A0% E3% 81% A7% E5% AD% A6% E3% 81% B6% E7% B7% 9A% E5% BD% A2% E4% BB% A3% E6% 95% B0-Philip-N-Klein / dp / 4873117771) p.19

Use Python to find the remainder of 2304811 divided by 47. However, do not use%.

How do you do it without using%! ?? I was addicted to it, so I made a note.

answer.py


2304811 - (2304811 // 47) * 47

Python has an operator called //, which is called truncation division.

sample.py


print(10 / 3)      # 3.33333333333333
print(10 // 3)     # 3
print(10 // 3.3)   # 3.0
print(10 % 3.3)    # 0.10000000000000053
print(10 // 3.4)   # 2.0
print(10 // 3.33)  # 3.0

For humans who entered from C, if you divide an integer value by an integer value, it will be rounded down and divided. I thought, but in a world without a mold, it seems that it will not go that way.

Recommended Posts

Modulo without using%
Bubble sort without using sort
Write FizzBuzz without using "="
Quicksort without using sort
Gamma correction without using OpenCV
[Python3] Google translate google translate without using api
Achieve enumeration modoki without using enum
Slice without using Python, colon (:). a.__getitem__ (slice (3,5)).
Save files using EC2 storage without using S3
Implement OAuth without using client library (Java)
Swap 1 and 2 without using an if statement
Use webcam without screen display using python-zbar
Using sqlacodegen
Change the output without touching the code using Argparse
Note: Periodically delete under / tmp without using tmpwatch