Skip to content

Commit 07700c5

Browse files
committed
Clang Attemp
1 parent 0b23d6b commit 07700c5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/main/java/com/thealgorithms/others/ShorAlgorithm.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import java.math.BigInteger;
44
import java.util.Random;
55

6-
//The algorithm is referred from
7-
//https://www.geeksforgeeks.org/shors-factorization-algorithm/
6+
// The algorithm is referred from
7+
// https://www.geeksforgeeks.org/shors-factorization-algorithm/
88
public class ShorAlgorithm {
9-
//trying to find the order of exponent given the base and the number
9+
// trying to find the order of exponent given the base and the number
1010
private int exponent(BigInteger base, BigInteger number) {
1111
BigInteger result = BigInteger.ONE;
1212
int increment = 0;
@@ -17,9 +17,9 @@ private int exponent(BigInteger base, BigInteger number) {
1717
return increment;
1818
}
1919

20-
//implementing the shor algorithm
20+
// implementing the shor algorithm
2121
public BigInteger[] shorAlgorithm(BigInteger number) {
22-
if(number.mod(new BigInteger("2")).equals(BigInteger.ZERO)) {
22+
if (number.mod(new BigInteger("2")).equals(BigInteger.ZERO)) {
2323
BigInteger p = number.divide(new BigInteger("2"));
2424
BigInteger q = new BigInteger("2");
2525
return new BigInteger[]{p, q};
@@ -32,20 +32,20 @@ public BigInteger[] shorAlgorithm(BigInteger number) {
3232
} while (base.compareTo(BigInteger.ZERO) <= 0 || base.compareTo(number) >= 0);
3333

3434
BigInteger hcf = base.gcd(number);
35-
if(hcf.compareTo(BigInteger.ONE) > 0) {
35+
if (hcf.compareTo(BigInteger.ONE) > 0) {
3636
return new BigInteger[]{hcf, number.divide(hcf)};
3737
}
3838

3939
int result = exponent(base, number);
40-
if(result % 2 != 0) return null;
40+
if (result % 2 != 0) return null;
4141

42-
BigInteger congruentResult = base.modPow(BigInteger.valueOf(result/2), number);
43-
if(congruentResult.equals(number.subtract(BigInteger.ONE))) return null;
42+
BigInteger congruentResult = base.modPow(BigInteger.valueOf(result / 2), number);
43+
if (congruentResult.equals(number.subtract(BigInteger.ONE))) return null;
4444

4545
BigInteger p = congruentResult.add(BigInteger.ONE).gcd(number);
4646
BigInteger q = congruentResult.subtract(BigInteger.ONE).gcd(number);
4747

48-
if(!p.equals(BigInteger.ONE) && !q.equals(BigInteger.ONE))
48+
if (!p.equals(BigInteger.ONE) && !q.equals(BigInteger.ONE))
4949
return new BigInteger[]{p, q};
5050
return null;
5151
}

0 commit comments

Comments
 (0)