18 Star 133 Fork 63

编程语言算法集 / C-Sharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
PollardsRhoFactorizing.cs 820 Bytes
一键复制 编辑 原始数据 按行查看 历史
Gerson Jr 提交于 2023-12-31 09:48 . Switch to file-scoped namespaces (#431)
using System;
using Algorithms.Numeric.GreatestCommonDivisor;
namespace Algorithms.Other;
/// <summary>Implementation of the Pollard's rho algorithm.
/// Algorithm for integer factorization.
/// Wiki: https://en.wikipedia.org/wiki/Pollard's_rho_algorithm.
/// </summary>
public static class PollardsRhoFactorizing
{
public static int Calculate(int number)
{
var x = 2;
var y = 2;
var d = 1;
var p = number;
var i = 0;
var gcd = new BinaryGreatestCommonDivisorFinder();
while (d == 1)
{
x = Fun_g(x, p);
y = Fun_g(Fun_g(y, p), p);
d = gcd.FindGcd(Math.Abs(x - y), p);
i++;
}
return d;
}
private static int Fun_g(int x, int p)
{
return (x * x + 1) % p;
}
}
C#
1
https://gitee.com/TheAlgorithms/C-Sharp.git
git@gitee.com:TheAlgorithms/C-Sharp.git
TheAlgorithms
C-Sharp
C-Sharp
master

搜索帮助