Solution Notes: The first step in solving this problem is writing a function to convert a number represented by a string in base N (here, N is 2 or 3) into an integer. This is done by the function convert_to_base_n() below. Once we have this function, the rest of the solution is just trying every possible solution to find the one that works - we look over every possible digit i of the base-2 number and every digit j of the base-3 number, and check whether we can make the two numbers evaluate to an equal amount by changing just these two digits. If so, this amount is our answer. The code below does this in a fairly concise manner by temporarily changing the two digits in question, testing the values of the resulting strings, and then putting the digits back the way they started. Digit i in the binary number is toggled between 0 and 1, and digit j in the base-3 number is cycled between 0, 1, and 2.

``````

#include <stdio.h&rt;
#include <stdlib.h&rt;
#include <string.h&rt;

int convert_to_base_n(char *s, int n)
{
int i = strlen(s), t=0, p=1;
while (i) {
i--;
t += p * (s[i] - '0');
p = p * n;
}
return t;
}

int main(void)
{
char A[100], B[100];
int lenA, lenB, i, j, k;
FILE *fp;

fp = fopen ("digits.in", "r");
fscanf (fp, "%s %s", A, B);
fclose (fp);

lenA = strlen(A);
lenB = strlen(B);

for (i=0; i<lenA; i++)
for (j=0; j<lenB; j++)
for (k=1; k<=2; k++) {
A[i]=((A[i]-'0')+1)%2+'0';
B[j]=((B[j]-'0')+k)%3+'0';
if (convert_to_base_n(A,2) == convert_to_base_n(B,3)) {
fp = fopen ("digits.out", "w");
fprintf (fp, "%d\n", convert_to_base_n(A,2));
fclose (fp);
return 0;
}
A[i]=((A[i]-'0')+1)%2+'0';
B[j]=((B[j]-'0')+3-k)%3+'0';
}
return 0;
}

``````