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

Method f2

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

Source from the content-addressed store, hash-verified

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) {
40 int o1 = (int) (a % mod); // a
41 int o2 = (int) (b % mod); // b
42 int o3 = (int) (c % mod); // c
43 int o4 = (int) (d % mod); // d
44 int o5 = (o1 + o2) % mod; // a + b
45 int o6 = (o3 - o4 + mod) % mod; // c - d
46 int o7 = (int) (((long) o1 * o3) % mod); // a * c
47 int o8 = (int) (((long) o2 * o4) % mod); // b * d
48 int o9 = (int) (((long) o5 * o6) % mod); // (a + b) * (c - d)
49 int o10 = (o7 - o8 + mod) % mod; // (a * c - b * d)
50 int ans = (o9 + o10) % mod; // ((a + b) * (c - d) + (a * c - b * d)) % mod
51 return ans;
52 }
53
54 public static void main(String[] args) {
55 System.out.println("测试开始");

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected