Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@@ -35,40 +35,40 @@ package com.thealgorithms.maths;
*
* */
public class PollardRho {
/**
* This method returns a polynomial in x computed modulo n
*
* @param base Integer base of the polynomial
* @param modulus Integer is value which is to be used to perform modulo operation over the polynomial
* @return Integer (((base * base) - 1) % modulus)
*/
static int g(int base,int modulus) {
return ((base * base) - 1) % modulus;
}
/**
* This method returns a non-trivial factor of given integer number
*
* @param number Integer is a integer value whose non-trivial factor is to be found
* @return Integer non-trivial factor of number
* @throws RuntimeException object if GCD of given number cannot be found
*/
static int pollardRho(int number) {
int x = 2, y = 2, d = 1;
while(d == 1) {
//tortoise move
x = g(x, number);
//hare move
y = g(g(y, number), number);
//check GCD of |x-y| and number
d = GCD.gcd(Math.abs(x - y), number);
}
if(d == number) {
throw new RuntimeException("GCD cannot be found.");
}
return d;
}
/**
* This method returns a polynomial in x computed modulo n
*
* @param base Integer base of the polynomial
* @param modulus Integer is value which is to be used to perform modulo operation over the polynomial
* @return Integer (((base * base) - 1) % modulus)
*/
static int g(int base, int modulus) {
return ((base * base) - 1) % modulus;
}
/**
* This method returns a non-trivial factor of given integer number
*
* @param number Integer is a integer value whose non-trivial factor is to be found
* @return Integer non-trivial factor of number
* @throws RuntimeException object if GCD of given number cannot be found
*/
static int pollardRho(int number) {
int x = 2, y = 2, d = 1;
while (d == 1) {
//tortoise move
x = g(x, number);
//hare move
y = g(g(y, number), number);
//check GCD of |x-y| and number
d = GCD.gcd(Math.abs(x - y), number);
}
if (d == number) {
throw new RuntimeException("GCD cannot be found.");
}
return d;
}
}