Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
10
Task/Modular-inverse/FutureBasic/modular-inverse.basic
Normal file
10
Task/Modular-inverse/FutureBasic/modular-inverse.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
NSInteger local fn ModularInverse2( a as NSInteger, b as NSInteger )
|
||||
a %= b
|
||||
for NSInteger x = 1 to b - 1
|
||||
if ( (a * x) % b == 1 ) then return x
|
||||
next
|
||||
end fn = -1
|
||||
|
||||
print fn ModularInverse2( 42, 2017 )
|
||||
|
||||
HandleEvents
|
||||
5
Task/Modular-inverse/Pluto/modular-inverse.pluto
Normal file
5
Task/Modular-inverse/Pluto/modular-inverse.pluto
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
local int = require "int"
|
||||
|
||||
local a = 42
|
||||
local b = 2017
|
||||
print(int.modinv(a, b))
|
||||
29
Task/Modular-inverse/Zig/modular-inverse.zig
Normal file
29
Task/Modular-inverse/Zig/modular-inverse.zig
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const std = @import("std");
|
||||
|
||||
fn mod_inv(a: isize, module: isize) isize {
|
||||
var mn_0 = module;
|
||||
var mn_1 = a;
|
||||
var xy_0: isize = 0;
|
||||
var xy_1: isize = 1;
|
||||
|
||||
while (mn_1 != 0) {
|
||||
const xy_0_temp = xy_1;
|
||||
xy_1 = xy_0 - @divFloor(mn_0, mn_1) * xy_1;
|
||||
xy_0 = xy_0_temp;
|
||||
|
||||
const mn_0_temp = mn_1;
|
||||
mn_1 = @rem(mn_0, mn_1);
|
||||
mn_0 = mn_0_temp;
|
||||
}
|
||||
|
||||
while (xy_0 < 0) {
|
||||
xy_0 += module;
|
||||
}
|
||||
|
||||
return xy_0;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
try stdout.print("{d}\n", .{mod_inv(42, 2017)});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue