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 8603505

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:20:24+00:00 2026-06-12T02:20:24+00:00

Here’s a question which deals with algorithm and bitwise xor operation. We are given

  • 0

Here’s a question which deals with algorithm and bitwise xor operation.
We are given x1*x2*x3*....*xn=P, where star(*) operation represents XOR(bitwise) operation and x1 to xn are positive integers. P is also a positive integer. We need to find min(a1+a2+a3+…..an) such that this relation holds–> (x1+a1)*(x2+a2)*(x3+a3)*....*(xn+an)=0. ‘+’ represents normal addition operation.

  • 0 0 Answers
  • 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-06-12T02:20:26+00:00Added an answer on June 12, 2026 at 2:20 am

    Restatement as a Bounded Integer Linear Programming Problem

    The problem can be restated as the following bounded ILP (integer linear programming) problem.

    Let x1,...,xN be as in the original problem, i.e. the goal is to minimize(a1+...+aN)
    under the conditions (x1+a1) XOR ... (xN+aN) = 0, a1,...,aN >= 0.
    
    The following is than an equivalent bounded ILP:
    Find b[k,i] (0 <= k <= K, 1 <= i <= N) and s[k] (0 <= k <= K) such that
      (A) b[k,i] in {0, 1} for all i=1..n, k=0..K,
      (B) s[k] is an integer >= 0 for all k=0..K,
      (C) sum(b[k,i]*2^k, k=0..K) >= x[i] for all i = 1..N,
      (D) sum(b[k,i], i=1..N) = 2*s[k] for all k = 0..K
    and minimize
      sum(b[k,i]*2^k, i=1..n, k=0..K).
    
    From a solution of the bounded ILP the ai's are obtained by
      a[i] = sum(b[k,i]*2^k, k=0..(K-1)) - x[i]
    

    b[k,i] is simply the k-th bit of the binary representation of (xi+ai) here (Conditions (A) and (C)). To make the overall XOR zero, an even number of b[k,i] must be 1 for every k. This is represented by conditions (B) and (D). (Note that the left-hand sum in (D) must be even if it’s equal to 2*s[k] and s[k] is an integer).

    K, i.e. the number of bits (plus one, actually) needed to represent all the (xi+ai) must to be determined beforehand. Picking a K such that all xi are < 2^K should suffice, i.e. the ai’s are most one bit larger than the largest xi. But picking a larger K doesn’t matter, the top bits will simply come out as zero. If K is picked to small, the ILP will have no solution.

    Existance of a Solution

    Ignoring the minimality condition, the problem can be restated as

    Given x, y z with x <= y, find a and b such that (x+a) XOR (y+b) = z

    Given an instance of your original problem, with N >= 2. Let x=x1, y=x2, z=(x3 XOR x4 XOR … xn). If you find suitable a and b, set a1=a, a2=b, a3=…=an=0 to obtain a solution of the original problem.

    The simplified problem is solved (again, ignoring minimality) by

    1. If (y XOR z) >= x then a: = ((y XOR z) – x), b := 0 is a solution (*)
    2. If (x XOR z) >= y then a := 0, b := ((x XOR z) – y) is a solution (*)
    3. Otherwise, pick an a such that (x+a) XOR z >= y. Such an a always exists, you can for example let a := 2^k with 2^k > max(x,y,z). Setting b := ((x+a) XOR z) – y) yields a solution (*)

    (*) To see that those really are solutions, you just need to applied a bit of algebra. For example, in case (1), after substituting a and b, you get: (x+(y XOR z)-x) XOR (y+0). Which is identical to: (y XOR z) XOR y, and thus to: z. q.e.d. Case (2) works similarly. In case (3) you get: (x+a) XOR (y+((x+a) XOR z)-y) = (x+a) XOR ((x+a) XOR z) = z.

    This shows that for N >= 2, a solution always exists.

    Whether or not those solutions are minimal, I do not know. In case (3), it quite obviously depends on the choice of a, so at the very least you’d have to figure out the optimal choice for a. It might also be that the original problem allows for smaller solutions than the simplified problem. Anway, maybe this restatement helps someone to figure out the complete solution.

    BTW, the fact that the original problems essentially leaves you total freedom of how to “spread out” the correction values ai over the xi makes me wonder if this isn’t equivalent to some sort of knapsack problem. If it is, finding a minimal solution might very well be NP-hard.

    Observations regarding minimality

    Take the following problem

    (1+a1) XOR (3+a2) XOR (6+a3) = 0
    

    In binary, that is

    (001b+a1) XOR (011b+a2) XOR (110b+a3) = 0
    

    The residue for a1=a2=a3=0 is 001b XOR 011b XOR 110b = 100b. An obvious solution is thus a1=4,a2=0,a3=0. Or alternatively a1=0,a2=4,a3=0. This solution is not minimal though – the following solution is smaller

    a1=1, a2=1, a3=0
    

    It’s also minimal, since all smaller solutions can only have one non-zero ai, and all of the terms (2 XOR 3 XOR 6), (1 XOR 4 XOR 6), (1 XOR 3 XOR 7) are non-zero.

    This shows that no gree algorithm which works from the bottom (i.e. lowest bit) upwards can work, since such an algorithm would skip the first two bits, since their residue is zero initially.

    It also shows that you cannot pick a certain non-zero bit k from the residue and attempt to zero it by adding 2^k to one of the xi’s. You sometimes have to add it to multiple xi’s to find the minimal solution.

    This pushes me a bit further towards believing that find a minimal solution is a comparatively hard problem.

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

Sidebar

Related Questions

Here a simple question : What do you think of code which use try
Here is my program to find all the subsets of given set. To solve
Here are some facts about my app followed by a question My app has
Here are the tables I have: Table A which has entries with item and
Here is my code, which takes two version identifiers in the form 1, 5,
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my work environment: Eclipse Juno as IDE with maven2 plugin on it

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.