Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the modular operation of multiplying and summing large numbers in C language?

Shulou Source: shulou.com Published: 2022-06-02 03:04:57 10月04日 Update

This article mainly analyzes the relevant knowledge points of the modular operation of multiplication and summation of large numbers in C language, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor to have a look. Let's go deep into the knowledge of "what the modular luck of multiplication and summation of large numbers in C language is like".

The problem is like the picture above, which is a common mathematical problem in programming or ACM, which is summarized with the experience of predecessors. (development language c)

# include

# define INT64 _ _ int64

INT64 PowerMode (INT64 basenum, INT64 powernum, INT64 modenum) {

/ / calculate basics ^ powernum% modenum

/ / a ^ (2c) = (a ^ c) ^ 2

/ / a ^ (2c+1) = a * ((a ^ c) ^ 2)

/ / for example, when we write b in binary form 13 (10) = 1101 (2)

/ / We operate from low bit to high bit, and each bit can move b to the right. The above example can be transformed into 3 ^ 13 = 3 ^ 1 * 3 ^ 4 * 3 ^ 8.

/ / (ahumb)% p = a% p * b% p% p

/ / (a ^ b)% p = (a% p) ^ b

/ / a ^ 13% m = (a ^ 8 * a ^ 4 * a ^ 1)% m = a ^ 8% m * a ^ 4% m * a ^ 1% m% m

INT64 result = 1

While (powernum) {

If (powernum&1)

Result = result * basenum% modenum

Basenum = basenum * basenum% modenum

Powernum > > = 1

}

Return result

}

INT64 MultiAdd (INT64 countnum, INT64 basenum, INT64 modenum) {

/ / (aqib)% p = (a% p + b% p)% p

/ /

INT64 sum = 0

For (int item0; I

Tags: Operations languages large numbers content knowledge followers topics pictures above binaries values low bits examples interests predecessors common forms mathematics articles easy to understand are in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Huawei vpn Redmi