Given a natural number \(\displaystyle{n}{ < }{10}^{{{9}}}\),

Liseskirlsojh

Liseskirlsojh

Answered question

2022-03-23

Given a natural number n<109, find the maximum number of the multiple of 3, which differs by exactly one digit from the given one

Answer & Explanation

sa3b4or9i9

sa3b4or9i9

Beginner2022-03-24Added 14 answers

Step 1
Let n=k=0s110kdk be an s-digit number when written in base 10.
Let tc= (kck=0s1dk) bmod3 be the sum, modulo 3, of all the digits except the c'th one.
The algorithm goes:
Set c=s1
Step 2
If digit dc<9tc, replace digit dc with 9tc and exit
Step 3
Set c=c1
If c0 return to Step 2.
If c<0 exit: there is no solution for this n.
A few examples follow.
n=523, t2=2, t1=2, t0 Step 2 (c=2) replaces the 5 with 92=7 and exits with 723
n=826, t2=2, t1=2, t0=1 Step 2 (c=2) decides that the 8 is too big to be replaced. Step 2 (c=1) replaces the 2 with 92=7 and exits with 876.
n=879, t2=1, t1=2, t0=0 . Step 2 decides that all the digits are too big to be replaced. (88, 77, 99). There is no solution for 879.

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?