Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:47:53+00:00 2026-05-23T10:47:53+00:00

I have multiple sets containing multiple congruences. I am trying to find the smallest

  • 0

I have multiple sets containing multiple congruences.

I am trying to find the smallest remainder when applying the Chinese remainder theorem on one item from each set.

For example with 2 sets:

Set 1:

7x + 1
7x + 3

Set 2:

11x
11x + 2
11x + 7
11x + 8

Taking 7x + 1 & 11x gives 77x + 22.
I am after the smallest remainder (in the above example 77x + 8) without having to test all combinations.


This is very simplified version of my actual problem (being ~50 sets, with ~100 congruences in each).

I am stuck on how to approach this problem, any advice would be greatly appreciated.

Also, my apologies if my math terminology is incorrect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:47:54+00:00Added an answer on May 23, 2026 at 10:47 am

    There is a meet-in-the middle algorithm that finds the smallest residue in time

    O(max(|S1|, |S2|) log(max(|S1|, |S2|))).

    First use the Chinese Remainder Theoremt to find the set T1 of all 0 <= t < n1*n2 satisfying t mod n1 in S1 and t mod n2 == 0
    and the set T2 of all 0 <= u < n1*n2 satisying t mod n1 == 0 and t mod n2 in S2.

    I.e. in the example given in the question:

    T1 = {22, 66}

    T2 = {0, 7, 35, 63}

    Now the residues you are looking for are the sums (t1 + t2) mod n1*n2, for any t1 in T1 and t2 in T2.
    Hence the smallest residue is either the sum of the two smallest elements in T1 and T2 or two elements that are just barely larger than n1*n2. If you sort the sets T1 and T2 then the best solution for the second case can be found by scanning the first set from the smallest to the largest element and scanning the largest set from the largest to the smalles element, i.e. advancing the position in T1 whenever the sum is smaller than n1*n2 and decreasing the position in T2 whenever it is larger than n1*n2.

    If you have more than two moduli n1 .. nk then the fastest solution I can see is to divide the moduli into two sets, say n1 .. nr and nr+1 .. nk find the set T1 such that t in T1 iff t mod ni in Si for all 1 <= i <= r and t mod ni == 0 for all r < i <= k. T2 is defined accordingly.
    The complexity depends on the distribution of the moduli, but should normally be about the square root of the number of possibilities. There is an algorithm by Schroeppel and Shamir, which can save some memory, but does not decrease the time complexity.

    For your application, i.e. 50 moduli and 100 congruences this algorithm still uses about 100^25 steps, which is infeasible. Unfortunately, it looks like there is no polynomial algorithm.
    In particular, it is known that finding the smallest solution x of the equation x^2 == a (mod n), where
    n is a highly composite integer is NP-complete. But finding such a solution can be reduced your problem.
    Hence, your problem should be NP-complete too in general unless the congruences have some special property that can be exploited.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an additional question from this . I have this array containing multiple
I have multiple results sets coming back from a server request against a datasource.
I have multiple winforms applications that download large sets of reference data on startup.
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select
I have multiple classes that all derive from a base class, now some of
I have multiple layers in an application and i find myself having to bubble
I have this find condition pulling from my model that currently looks like this.
I have multiple sets of code I need to run in Access 2007 and
I have multiple sets of xy pairs that I want to plot. I want
I have a pattern like this that matches multiple sets of values: (((\w+) (\d+))+)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.