This one is quick and interesting.
Natural number ends with 2.If we remove this 2 and place it at the beginning, the number gets doubled.Find the smallest possible original number.
(e.g. number is say 142. New number will be 214. 214 is not twice 142 so 142 is not such number).
MH
palanisamy subramani
Greenhorn
Joined: Aug 30, 2010
Posts: 28
posted
0
I tried all the possible way. This is the only number coming very nearer but not as per your expected result.
1052:2105.
I am suspecting whether that question has any answer.
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2127
posted
0
palanisamy subramani wrote:I tried all the possible way.
Really? All of them?
Arjun Shastry
Ranch Hand
Joined: Mar 13, 2003
Posts: 1828
posted
0
I found the number.Its quite big.Let others try.
anirudh jagithyala
Ranch Hand
Joined: Dec 07, 2010
Posts: 41
posted
1
Hey Arjun,
I tried out the problem and found the answer as:105263157894736842
Not sure whether it is the smallest one.....is it right...?
Arjun Shastry
Ranch Hand
Joined: Mar 13, 2003
Posts: 1828
posted
0
anirudh jagithyala wrote:Hey Arjun,
I tried out the problem and found the answer as:105263157894736842
Not sure whether it is the smallest one.....is it right...?
i too found the same number but not sure its smallest one.Waiting for others.
Paul Clapham wrote:No need to wait... the title of this forum is Programming Diversions. While the question is certainly diverting, I haven't seen any programming yet.
Maybe you could interpret the title as 'diversions AWAY from programming', thus no programming required.
Never ascribe to malice that which can be adequately explained by stupidity.
So, we just look for a value of n that makes x an integer ending with 2. The n vs (n+1) doesn't matter, but the -4 vs -2 will produce different answers.
So the answer is 105263157894736842. The check for the last digit being 2 turned out to be unnecessary, but I think that's a coincidence.
ETA: In reading through Mike's solution, I see the -4 makes sense if you declare x to be the number without the final 2. Sorry about that!
I wonder if we can prove we don't have to check the final digit, as both Mike and I discovered?
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2127
posted
0
Eugene is quoting the same formula I used above. And we got the same answer - except that as I noted above, my 'x' represented all the digits other than the 2. So I got
I tried some thing very simple and may sound very stupid....
BigInteger i,a,b;
for(i=0;i<100000000000000;i++)
{
String x,y;
String num = Integer.toString(i);
x = num+"2";
y = "2"+num;
int a = Integer.parseInt(x);
int b = Integer.parseInt(y);
if(a==(b/2))
System.out.println(a+" "+b);
}
did not get any no...though....
SCJP
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2127
posted
0
Rohini Sahuji wrote:did not get any no...though....
It's possible this is caused by the fact that your code does not compile. That's just a guess though.