MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / f1

Method f1

src/class041/Code03_SameMod.java:15–36  ·  view source on GitHub ↗
(long a, long b, long c, long d, int mod)

Source from the content-addressed store, hash-verified

13
14 // 计算 ((a + b) * (c - d) + (a * c - b * d)) % mod 的非负结果
15 public static int f1(long a, long b, long c, long d, int mod) {
16 BigInteger o1 = new BigInteger(String.valueOf(a)); // a
17 BigInteger o2 = new BigInteger(String.valueOf(b)); // b
18 BigInteger o3 = new BigInteger(String.valueOf(c)); // c
19 BigInteger o4 = new BigInteger(String.valueOf(d)); // d
20 BigInteger o5 = o1.add(o2); // a + b
21 BigInteger o6 = o3.subtract(o4); // c - d
22 BigInteger o7 = o1.multiply(o3); // a * c
23 BigInteger o8 = o2.multiply(o4); // b * d
24 BigInteger o9 = o5.multiply(o6); // (a + b) * (c - d)
25 BigInteger o10 = o7.subtract(o8); // (a * c - b * d)
26 BigInteger o11 = o9.add(o10); // ((a + b) * (c - d) + (a * c - b * d))
27 // ((a + b) * (c - d) + (a * c - b * d)) % mod
28 BigInteger o12 = o11.mod(new BigInteger(String.valueOf(mod)));
29 if (o12.signum() == -1) {
30 // 如果是负数那么+mod返回
31 return o12.add(new BigInteger(String.valueOf(mod))).intValue();
32 } else {
33 // 如果不是负数直接返回
34 return o12.intValue();
35 }
36 }
37
38 // 计算 ((a + b) * (c - d) + (a * c - b * d)) % mod 的非负结果
39 public static int f2(long a, long b, long c, long d, int mod) {

Callers 1

mainMethod · 0.95

Calls 3

modMethod · 0.80
addMethod · 0.45
multiplyMethod · 0.45

Tested by

no test coverage detected