Home Common Problem What does mod mean in algorithm?

What does mod mean in algorithm?

Aug 29, 2020 pm 12:43 PM
mod algorithm

In the algorithm, mod means taking the modulo, which is taking the remainder. The mod operation, that is, the remainder operation, is an operation that finds the remainder of dividing an integer x by another integer y in integer operations, without considering the quotient of the operation.

What does mod mean in algorithm?

The mod operation, that is, the remainder operation, is an operation that finds the remainder of dividing an integer x by another integer y in integer operations, regardless of the operation. quotient. There is MOD operation in computer programming, and its format is: mod(nExp1,nExp2), which is the remainder after dividing two numerical expressions.

Modulo p operation editor

Given a positive integer p and any integer n, there must be an equation

n = kp r where k , r is an integer, and 0 ≤ r

For positive integer p and integers a and b, the following operation is defined:

Modulo operation: a mod p represents the remainder of dividing a by p.

Addition modulo p: (a b) mod p, the result is the remainder of the arithmetic sum of a b divided by p, that is, (a b) = kp r, then (a b) mod p = r.

Modul p subtraction: (a-b) mod p, the result is the remainder of the arithmetic difference a-b divided by p.

Modul p multiplication: (a × b) mod p, the result is the remainder of the a × b arithmetic multiplication divided by p.

It can be found that the modular p operation has many similar rules to the four ordinary arithmetic operations, such as:

Associative Law
((a b) mod p c)mod p = (a (b c) mod p) mod p
((a*b) mod p * c)mod p = (a * (b*c) mod p) mod p
COMmutativity
(a b) mod p = (b a ) mod p
(a × b) mod p = (b × a) mod p
##distributive law
((a b)mod p × c) mod p = ((a × c) mod p (b × c) mod p) mod p
(a×b) mod c= (a mod c * b mod c) mod c
(a b) mod c=(a mod c b mod c) mod c
(a-b) mod c=(a mod c- b mod c ) mod c
Simple proof of the first formula:

((a b) mod p c) mod p = (a (b c) mod p) mod p

Assume

a = k1*p r1

b = k2*p r2

c = k3*p r3

a b = (k1 k2) p (r1 r2)

If (r1 r2) >= p, then

(a b) mod p = (r1 r2 ) -p

Otherwise

(a b) mod p = (r1 r2)

Then perform modulo p sum operation with c, and the result is

The remainder of the arithmetic sum of r1 r2 r3 divided by p.

The same result can be obtained by calculating the right side, and the proof is obtained.

Equal modulo p

If two numbers a and b satisfy a mod p = b mod p, then they are said to be equal modulo p, denoted as

a ≡ b (mod p)

It can be proved that at this time, a and b satisfy a = kp b, where k is an integer.

For equality modulo p and multiplication modulo p, there is a completely different rule from the four arithmetic operations. In the four arithmetic operations, if c is a non-0 integer, then

ac = bc can be obtained as a =b

. However, in the modulo p operation, this relationship does not exist, for example:

(3 x 3) mod 9 = 0

(6 x 3) mod 9 = 0

But

3 mod 9 = 3

6 mod 9 =6

Theorem (elimination law): If gcd(c,p) = 1, then ac ≡ bc mod p can deduce a ≡ (b mod p)

Proof:

Because ac ≡ bc (mod p)

so ac = bc kp, that is, c(a-b) = kp

Because c and p are not divided by 1 Common factors other than , then c|kp

Because c and p have no common factors, it is obvious that c|k, so k = ck'

Therefore c(a-b)=kp can be expressed as c(a-b) =ck'p

Therefore a-b = k'p, it follows that a ≡ b (mod p)

If a = b, then a ≡ b mod p is obviously true

得证

For more related knowledge, please visit:

PHP中文网

!

The above is the detailed content of What does mod mean in algorithm?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to uninstall/delete MOD in OpenIV How to uninstall/delete MOD in OpenIV Feb 18, 2024 pm 04:25 PM

OpenIV is a popular game modification tool, mainly used in the Grand Theft Auto (GTA) series of games. Although using mods can add new features and improve the experience to the game, sometimes we may need to delete installed mods for various reasons. This article will explain how to remove mods using OpenIV. First, make sure you have the OpenIV tools installed. For users who have not installed it, you can download it from the OpenIV official website (https://www.ope

Cyberpunk 2077 sees up to a 40% performance boost with new optimized path tracing mod Cyberpunk 2077 sees up to a 40% performance boost with new optimized path tracing mod Aug 10, 2024 pm 09:45 PM

One of the standout features ofCyberpunk 2077is path tracing, but it can put a heavy toll on performance. Even systems with reasonably capable graphics cards, such as the RTX 4080 (Gigabyte AERO OC curr. $949.99 on Amazon), struggle to offer a stable

CLIP-BEVFormer: Explicitly supervise the BEVFormer structure to improve long-tail detection performance CLIP-BEVFormer: Explicitly supervise the BEVFormer structure to improve long-tail detection performance Mar 26, 2024 pm 12:41 PM

Written above & the author’s personal understanding: At present, in the entire autonomous driving system, the perception module plays a vital role. The autonomous vehicle driving on the road can only obtain accurate perception results through the perception module. The downstream regulation and control module in the autonomous driving system makes timely and correct judgments and behavioral decisions. Currently, cars with autonomous driving functions are usually equipped with a variety of data information sensors including surround-view camera sensors, lidar sensors, and millimeter-wave radar sensors to collect information in different modalities to achieve accurate perception tasks. The BEV perception algorithm based on pure vision is favored by the industry because of its low hardware cost and easy deployment, and its output results can be easily applied to various downstream tasks.

Rabbit R1 gets modded to run games, performs better than expected Rabbit R1 gets modded to run games, performs better than expected Jun 29, 2024 am 07:50 AM

Earlier this month, a YouTuber named HowToMen showcased the Rabbit R1 running Android. With this mod, the device that was originally meant to be less distracting than a phone got to function like one. That isn't a bad thing, though, as Rabbit didn't

Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions Jun 03, 2024 pm 01:25 PM

Common challenges faced by machine learning algorithms in C++ include memory management, multi-threading, performance optimization, and maintainability. Solutions include using smart pointers, modern threading libraries, SIMD instructions and third-party libraries, as well as following coding style guidelines and using automation tools. Practical cases show how to use the Eigen library to implement linear regression algorithms, effectively manage memory and use high-performance matrix operations.

Explore the underlying principles and algorithm selection of the C++sort function Explore the underlying principles and algorithm selection of the C++sort function Apr 02, 2024 pm 05:36 PM

The bottom layer of the C++sort function uses merge sort, its complexity is O(nlogn), and provides different sorting algorithm choices, including quick sort, heap sort and stable sort.

Can artificial intelligence predict crime? Explore CrimeGPT's capabilities Can artificial intelligence predict crime? Explore CrimeGPT's capabilities Mar 22, 2024 pm 10:10 PM

The convergence of artificial intelligence (AI) and law enforcement opens up new possibilities for crime prevention and detection. The predictive capabilities of artificial intelligence are widely used in systems such as CrimeGPT (Crime Prediction Technology) to predict criminal activities. This article explores the potential of artificial intelligence in crime prediction, its current applications, the challenges it faces, and the possible ethical implications of the technology. Artificial Intelligence and Crime Prediction: The Basics CrimeGPT uses machine learning algorithms to analyze large data sets, identifying patterns that can predict where and when crimes are likely to occur. These data sets include historical crime statistics, demographic information, economic indicators, weather patterns, and more. By identifying trends that human analysts might miss, artificial intelligence can empower law enforcement agencies

Improved detection algorithm: for target detection in high-resolution optical remote sensing images Improved detection algorithm: for target detection in high-resolution optical remote sensing images Jun 06, 2024 pm 12:33 PM

01 Outlook Summary Currently, it is difficult to achieve an appropriate balance between detection efficiency and detection results. We have developed an enhanced YOLOv5 algorithm for target detection in high-resolution optical remote sensing images, using multi-layer feature pyramids, multi-detection head strategies and hybrid attention modules to improve the effect of the target detection network in optical remote sensing images. According to the SIMD data set, the mAP of the new algorithm is 2.2% better than YOLOv5 and 8.48% better than YOLOX, achieving a better balance between detection results and speed. 02 Background & Motivation With the rapid development of remote sensing technology, high-resolution optical remote sensing images have been used to describe many objects on the earth’s surface, including aircraft, cars, buildings, etc. Object detection in the interpretation of remote sensing images