俄罗斯农民算法用于乘以两个数字。这是一个快速计算两个长数字乘法的算法。算法开始 俄罗斯农民(num1, num2) Int result=0 while (num2 > 0) if (num2 and 1) result = result + n; num1= num1 左移 1; num2= num2左移 1; 返回结果 结束示例代码#include using namespace std; unsigned int russianPeasant(unsigned int n, unsigned int m) { int result = 0; while (m > 0) { if (m & 1) result = result + n; n = n > 1; } return result; } int main() { cout
Schonhage-Strassen算法用于乘以两个数字。Schonhage-Strassen算法是一种渐近快速的大整数乘法算法。在实践中,Schonhage-Strassen算法开始胜过Karatsuba和Toom-Cook等旧方法,其数字超过2215到2217(10,000到40,000十进制)位。算法开始 function noOfDigit( x) 声明一个变量n并赋值n = 0; while (x > 0) x = x /10 递增n 返回n 结束 开始 SchonhageStrassenMultiplication算法: schonhageStrassenMultiplication(a, b, n, m) 定义一个数组linearConvolution[n + m ... 阅读更多
费马素性测试用于检查给定数字是否为素数。以下是该算法的C++代码。算法开始 modulo(base, e, mod) a = 1 b = base while (e > 0) if (e mod 2 == 1) a = (a * b) % mod b = (b * b) % mod e = e / 2 返回a % mod 结束 开始 Fermat(ll m, int iterations) if (m == 1) ... 阅读更多
Rabin-Miller素性测试用于检查给定数字是否为素数。它类似于格式素性测试和Solovay-Strassen测试。该测试首先由俄罗斯数学家M. M. Artjuhov发现。算法开始 ll mulmod(ll a, ll b, ll m) ll x = 0, y = a mod m while (b > 0) if (b mod 2 == 1) 计算x = (x + y) mod m y = (y * 2) mod m b = b/ 2 ... 阅读更多