10677  Base Equality
Moderator: Board moderators
10677  Base Equality
I agree that (1040)16%(1040)10=0 and (4240)16%(4240)10=0. But it seems that (9240)14%(9240)11!=0, or I misunderstand the problem?

 Learning poster
 Posts: 63
 Joined: Mon Dec 22, 2003 5:05 am
 Location: Russia, Chelyabinsk
 Contact:
Re: 10677
In problem description one said:htl wrote:I agree that (1040)16%(1040)10=0 and (4240)16%(4240)10=0. But it seems that (9240)14%(9240)11!=0, or I misunderstand the problem?
Firstly, you have to translate 9240 in base 14.Notice that all numbers in the input are given in the base 10
First, I thought all the numbers in the input are given in base ten. But, then I found that, the range is to be treated in b1.
So, the task is actually simple,
for loop between the limit given,
for each iterated value,
convert it in b1, and then b2.
then check whether b2%b1==0
if yes, then break and print.
if none, then print not consistant.

easiest problem in the contest.
So, the task is actually simple,
for loop between the limit given,
for each iterated value,
convert it in b1, and then b2.
then check whether b2%b1==0
if yes, then break and print.
if none, then print not consistant.

easiest problem in the contest.
"Everything should be made simple, but not always simpler"
[c]#include <iostream>
using namespace std;
long trans(int v,int b) {
long n = 0;
long t = 1;
while(v>0) {
n += t * (v % 10);
v /= 10;
t *= b;
}
return n;
}
void start() {
long b1,b2,r1,r2;
cin >> b1 >> b2 >> r1 >> r2;
long i,j,k;
for(i=r21;i>r1;i) {
if(trans(i,b2) % trans(i,b1)==0) {
cout << i << endl;
return;
}
}
cout << "Nonexistent." << endl;
}
int main() {
int t;
cin >> t;
while(t) start();
return 0;
}[/c]
Same problem as htl....
My trans(9240,11) gives 12265 while trans(9240,14) gives 25144........ which means that 9240 is not a valid number.... my program spits out 6996 for the last input....
Any suggestions?
using namespace std;
long trans(int v,int b) {
long n = 0;
long t = 1;
while(v>0) {
n += t * (v % 10);
v /= 10;
t *= b;
}
return n;
}
void start() {
long b1,b2,r1,r2;
cin >> b1 >> b2 >> r1 >> r2;
long i,j,k;
for(i=r21;i>r1;i) {
if(trans(i,b2) % trans(i,b1)==0) {
cout << i << endl;
return;
}
}
cout << "Nonexistent." << endl;
}
int main() {
int t;
cin >> t;
while(t) start();
return 0;
}[/c]
Same problem as htl....
My trans(9240,11) gives 12265 while trans(9240,14) gives 25144........ which means that 9240 is not a valid number.... my program spits out 6996 for the last input....
Any suggestions?
Read the following input description
" Notice that all numbers in the input are given in the base 10."
So, 9240 is a 10 based number. Now, convert it in B1(11) based number
and take the digits (6)(10)(4)(0). I have parenthesized a single digit.
Now assume that it is a base B2(14) number and convert it to base 10.
the number is
6*14^3 + 10*14^2 + 4*14^1 + 0*14^0 = 18480 (base 10)
And 18480 / 9240 = 2 = c.
Hope this will help to understand the problem.
" Notice that all numbers in the input are given in the base 10."
So, 9240 is a 10 based number. Now, convert it in B1(11) based number
and take the digits (6)(10)(4)(0). I have parenthesized a single digit.
Now assume that it is a base B2(14) number and convert it to base 10.
the number is
6*14^3 + 10*14^2 + 4*14^1 + 0*14^0 = 18480 (base 10)
And 18480 / 9240 = 2 = c.
Hope this will help to understand the problem.