I want to get the shortest sequence to reach a number.Rules:A[0] is always 1Either A[i] = A[i-1]*2 or A[i] = A[i-1]+1For example, if my input number is 17, my output should be 6, becauseA[0]=1, A[1]=2, A[2]=4, A[3]=8, A[4]=16, A[5]=17The following code is not working properly for few inputs, such as 15.public static int GetMinimumSequence(int n)        {            if (n == 1)                return 1;            int count = 1;            int temp = 1;            for (int i = 2; i <= n; i++)            {                temp = temp * 2;                if (temp >= n)                {                    temp = temp/2;                    temp = temp + 1;                }                count++;                if(temp == n)                    break;            }            return count;        }
Getting the shortest sequence to reach a number
c#;algorithm;pathfinding