📌  相关文章
📜  (i * j)%的最小可能值2019(1)

📅  最后修改于: 2023-12-03 14:58:59.753000             🧑  作者: Mango

Introduction to finding the minimum possible value of (i * j) % 2019

In this guide, we will discuss the problem of finding the minimum possible value of the expression (i * j) % 2019, where i and j are integers. This problem is often encountered in competitive programming or algorithmic contests.

Problem Statement

Given the expression (i * j) % 2019, we want to find the minimum possible value of the expression. The input consists of two integers i and j.

Approach

To find the minimum possible value of the expression (i * j) % 2019, we need to consider the divisors of 2019.

2019 can be factored into prime factors as 3 * 673.

Now, let's consider four cases based on the values of i and j:

Case 1: i or j is divisible by 3 and not divisible by 673

In this case, (i * j) % 2019 will be 0 as one of the numbers is divisible by 3. Therefore, the minimum possible value is 0.

Case 2: i or j is divisible by 673 and not divisible by 3

In this case, (i * j) % 2019 will be equal to (i * j) % 673, as 2019 is a multiple of 673. Therefore, the minimum possible value is (i * j) % 673.

Case 3: i is divisible by 3 and j is divisible by 673

In this case, (i * j) % 2019 will also be 0 as both i and j are divisible by 3 and 673. Therefore, the minimum possible value is 0.

Case 4: Neither i nor j is divisible by 3 or 673

In this case, we need to consider the values of i * j % 3 and i * j % 673 separately. We can then find the minimum possible value by finding the smallest non-zero remainder for both cases.

Pseudocode

Here's a pseudocode representation of the algorithm:

function findMinimum(i, j):
    if i % 3 == 0 or j % 3 == 0:
        return 0
    else if i % 673 == 0 or j % 673 == 0:
        return (i * j) % 673
    else:
        minRemainder = 2019
        for k = 1 to 2018:
            remainder = (i * j) % 2019
            if remainder != 0:
                minRemainder = min(minRemainder, remainder)
            i++
            j++
        return minRemainder
Complexity Analysis

The complexity of this approach is O(2019) because we iterate through all possible values of i and j. However, since 2019 is a relatively small number, the algorithm runs in a reasonable amount of time.

Conclusion

In this guide, we discussed the problem of finding the minimum possible value of the expression (i * j) % 2019. We analyzed different cases based on the values of i and j and provided a solution using pseudocode. By considering the prime factors of 2019, we were able to find the minimum possible value efficiently.