Data update
This commit is contained in:
parent
61b93a2cd1
commit
5af6d93694
858 changed files with 20572 additions and 2082 deletions
22
Task/Modular-inverse/Java/modular-inverse-2.java
Normal file
22
Task/Modular-inverse/Java/modular-inverse-2.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
public final class ModularInverse {
|
||||
|
||||
public static void main(String[] aArgs) {
|
||||
System.out.println(inverseModulus(42, 2017));
|
||||
}
|
||||
|
||||
private static Egcd extendedGCD(int aOne, int aTwo) {
|
||||
if ( aOne == 0 ) {
|
||||
return new Egcd(aTwo, 0, 1);
|
||||
}
|
||||
Egcd value = extendedGCD(aTwo % aOne, aOne);
|
||||
return new Egcd(value.aG, value.aY - ( aTwo / aOne ) * value.aX, value.aX);
|
||||
}
|
||||
|
||||
private static int inverseModulus(int aNumber, int aModulus) {
|
||||
Egcd value = extendedGCD(aNumber, aModulus);
|
||||
return ( value.aG == 1 ) ? ( value.aX + aModulus ) % aModulus : 0;
|
||||
}
|
||||
|
||||
private static record Egcd(int aG, int aX, int aY) {}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
function modinv{T<:Integer}(a::T, b::T)
|
||||
function modinv(a::T, b::T) where T <: Integer
|
||||
b0 = b
|
||||
x0, x1 = zero(T), one(T)
|
||||
while a > 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue