Here is the problem:-Click Here.
.I have been trying it for more time but not getting how to solve the polynomial equation after converting from base 'b' to decimal i.e. my algorithm is:-
size of array = max(A.size(),B.size(),Z.size());
store A in array as int;
add B as int element by element;
subtract Z as int element by element;
now we get cofficients of a polynomial in b i.e x1b^n + x2b^(n-1) + ...... + xn*b^0 = 0;
How to solve it or is there any other method for it??
Thanks in advance.

Recommended Answers

All 12 Replies

There is no polynomial. It a simple addition or multiplication problem.

Convert A to int.
Store operator.
Convert B to int.
Convert Z to int.
Calculate A operator B.
Compare with Z.

Easy-peasy.

How would you convert a2c3 to int?

How do you convert 120 to int?

What base is A2C3?

I m not getting you.Can u explain a complex example of this problem involving both letters and digits.Thanks.
By the way 120 can be of any base from 3 to inf.

How do you take the string of characters '1','2','0' and turn them into the integer 120?

By the way 120 can be of any base from 3 to inf.

Yes it could. Ignore that for the moment.

By the way 120 can be of any base from 3 to inf.

Thats exactly what hes getting at. If you want to convert A2C3 you have to say what base it is in because this could be anything from base 13 to infinity the way you see it.

If you are assuming that A2C3 is in hex then you can loop through the string, converting each hex char to decimal and then add it to an integer variable.

#include <iostream>
#include <cmath>
using namespace std;

int hex2dec(string hexstr)
{
    int decval = 0;

    for( unsigned int i = 0; i < hexstr.size(); i++ )
        if( hexstr[i] >= '1' && hexstr[i] <= '9' )
            decval += (hexstr[i] - '0')*pow(16, hexstr.size()-1-i);
        else if( toupper(hexstr[i]) >= 'A' && toupper(hexstr[i]) <= 'F' )
            decval += (toupper(hexstr[i]) - 'A' + 10)*pow(16, hexstr.size()-1-i);

    return decval;
}

int main()
{
    int num = 0xA2C3;
    cout << num << endl;
    cout << hex2dec("A2C3") << endl;

    cin.get();
    return 0;
}

But the code has nothing to do with the problem.The base of the number identity in test case is unknown.So my question is straight forward that is there any other way (other than making polynomial equation in general base b) for doing this problem in minimum computational complexity ? If yes,please give an instance of the algorithm.Thanks.

Actually the code post is exactly what you wanted for the whole conversion from one base to another. This is just set to hex, if you want to it be general then replace all the 16s with a variable and expand the alphabet to Z.

You can write a check minimum base function and pass A, B and Z/R into it then run a loop checking to see if A + B = Z and A x B = R with the current base, if not then check the next. If you hit the maximum allowable base then return 0. If you find a base that works then run it to the end to see if it is unique or not.

If you cannot figure this out now then you are hopeless!

And my question is also exactly what you need to consider.

Now, answer my question...

ok guys there is another problem:-

OK guy, here our problem.

You won't respond to our questions, just post new questions.
You don't give us any indication that out help was useful. All you did was complain about our answers.
For all we know you dropped the original question because it was too hard and we wouldn't write it for you.

Why should we waste our time on new questions?

oh no!! Don't get me wrong..I had solved it that day.Again sorry for not posting.Actually in the question there was a limit of 2^64-1 which I utilize to find the bases of 1st equation and than utilizing all these solutions in rest of equations to determine common solutions.All I did was just run a loop from minimum base and ended it when any of A || B || C exceeds 2^64-1.This gave me solution for 1st equation.
Thanks Waltp and sfuo for your suggestions!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.