Help me to understand this question

Pages: 12
Oct 6, 2018 at 5:16pm
You are given positive integers N and D. You may perform operations of the following two types:

1- add D to N, i.e. change N to N+D
2- change N to digitsum(N)
Here, digitsum(x) is the sum of decimal digits of x. For example, digitsum(123)=1+2+3=6 and digitsum(100)=1+0+0=1.

You may perform any number of operations (including zero) in any order. Please find the minimum obtainable value of N and the minimum number of operations required to obtain this value.

Example Input
3
2 1
9 3
11 13
Example Output
1 9
3 2
1 4

Explanation
Example case 1: The value N=1 can be achieved by 8 successive "add" operations (changing N to 10) and one "digit-sum" operation.
Oct 6, 2018 at 6:05pm
You get given two numbers.

You can transform the first number into another number.
There are two ways you can do that transformation.

You have to make that first number as small as possible, by doing those transformations.

So do that. Make it as small as possible, in as few transformations as possible.


Oct 7, 2018 at 9:22am
Can anyone give hint in this question?
Oct 7, 2018 at 10:17am
What algorithms have you experimented with already?
Oct 7, 2018 at 10:44am
Deleted
Last edited on Oct 7, 2018 at 3:29pm
Oct 7, 2018 at 2:19pm
Why would your algorithm give the minimum value of N? Why would it give the minimum number of steps to achieve N? If I say that step 2 should loop 9455 times instead of 10^4, then would I be right or wrong? Why? What if I said that the number is N2-4D/3?

You need to think about the algorithm and the steps. Don't worry about the code until you're sure about the algorithm. After all, there's no point in committing an algorithm to code when you don't know what the algorithm is.
Oct 7, 2018 at 3:46pm
can anyone drop a hint please ?
Last edited on Oct 7, 2018 at 3:52pm
Oct 7, 2018 at 7:33pm
.
Last edited on Oct 9, 2018 at 1:00am
Oct 8, 2018 at 8:53am
2 4
8 0
1 10
1 5
1 11
1 8
1 2
1 3
1 3
1 10
Oct 8, 2018 at 8:56am
@Repeater I had figured out the algorithm but some test cases are showing WA. I'm quite sure I am missing some boundary cases. Can you give me some edge cases to debug my code?
Oct 8, 2018 at 11:45am
@pplo123, same here mate, im getting one WA in subtask 1, and three WA in subtask 2.
yeah, we are definitely missing some corner cases.
Could anyone please drop a good input in order to debug the code
Oct 8, 2018 at 12:53pm
@maxdaen I am getting the same test cases wrong. Please someone gives us some edge cases.
Oct 8, 2018 at 2:06pm
@pplo123
Can you show your code as to make some improvements?
Oct 8, 2018 at 3:03pm
any one getting task number 6 AC ??.. i am getting failed at that one task
Oct 8, 2018 at 3:41pm
.
Last edited on Oct 9, 2018 at 2:18am
Oct 8, 2018 at 6:31pm
@pplo123, Your answer for 95,83 is wrong. It should be 1,9 (add 83 6 times, add digits, add 83, add digits).
Oct 8, 2018 at 6:59pm
please can any one just give a hint on how should we start this question?I am not getting any kind of hint on how to do this question .Thanks.
Oct 8, 2018 at 7:02pm
i did it using complete binary tree 100% AC
Oct 8, 2018 at 7:10pm
@tpd Thanks for finding the error.
Oct 9, 2018 at 5:20am
pplo123 have you solved mindsum?
Pages: 12