Play with number system problem on Hackerblocks

Can anyone tell me what is wrong in this code ? It works perfectly fine while giving outputs of any manual test cases, but the given test cases do not pass. Please help me.

#include
#include
#include

using namespace std;

int main(){

long int sb,db,sn;
string dn;
cin >> sb >> db >> sn;

int p = 1, decimalNumber;

while( sn > 0){
	int last_digit = sn % 10;
	decimalNumber = decimalNumber + ( last_digit * p);
	p = p * sb;
	sn = sn / 10;
}

if(db == 10 ){
	cout << decimalNumber;
	exit(0);
}
else{
	while(decimalNumber > 0){
		int last_digit = decimalNumber % db;
		dn = to_string( last_digit ) + dn; 
		decimalNumber = decimalNumber / db;
	}
}

cout << dn;

return 0;

}