Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report