using System; public class Test { public static int GetMinimumSequence200(int n) { if (n <= 0) { throw new ArgumentOutOfRangeException(); } else if (n == 1) { return 1; } else if ((n % 2) == 1) { return 1 + GetMinimumSequence200(n - 1); } else { return 1 + Math.Min(GetMinimumSequence200(n - 1), GetMinimumSequence200(n / 2)); } } public static int GetMinimumSequenceOP(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; } public static int GetMinimumSequence(int n) { int prevexponent = (int)Math.Log(n, 2); return 1 + prevexponent + n - (1 << prevexponent); } public static int GetMinimumSequenceCW(int n) { if (n <= 0) throw new ArgumentOutOfRangeException(); for (int i = 1; ; ++i) { if (n == 1) return i; if ((n % 2) == 0) n /= 2; else n -= 1; } } public static int GetMinimumSequenceRL(int n) { int cnt = 0; while (n > 0) { cnt++; n = (n % 2 == 0) ? (n / 2) : (n - 1); } return cnt; } public static void Main() { for (int i = 1; i <= 100; i++) { Console.Write("Input " + i + " -> " + " OP " + GetMinimumSequenceOP(i) + " R2 " + Test.GetMinimumSequence(i) // Rolfl v2 + " R3 " + GetMinimumSequenceRL(i) // Rolfl v3 + " CW " + GetMinimumSequenceCW(i) + " 2S " + GetMinimumSequence200(i) + "\n"); } } }
Standard input is empty
Input 1 -> OP 1 R2 1 R3 1 CW 1 2S 1 Input 2 -> OP 2 R2 2 R3 2 CW 2 2S 2 Input 3 -> OP 3 R2 3 R3 3 CW 3 2S 3 Input 4 -> OP 4 R2 3 R3 3 CW 3 2S 3 Input 5 -> OP 4 R2 4 R3 4 CW 4 2S 4 Input 6 -> OP 5 R2 5 R3 4 CW 4 2S 4 Input 7 -> OP 6 R2 6 R3 5 CW 5 2S 5 Input 8 -> OP 7 R2 4 R3 4 CW 4 2S 4 Input 9 -> OP 5 R2 5 R3 5 CW 5 2S 5 Input 10 -> OP 6 R2 6 R3 5 CW 5 2S 5 Input 11 -> OP 7 R2 7 R3 6 CW 6 2S 6 Input 12 -> OP 8 R2 8 R3 5 CW 5 2S 5 Input 13 -> OP 9 R2 9 R3 6 CW 6 2S 6 Input 14 -> OP 10 R2 10 R3 6 CW 6 2S 6 Input 15 -> OP 11 R2 11 R3 7 CW 7 2S 7 Input 16 -> OP 12 R2 5 R3 5 CW 5 2S 5 Input 17 -> OP 6 R2 6 R3 6 CW 6 2S 6 Input 18 -> OP 7 R2 7 R3 6 CW 6 2S 6 Input 19 -> OP 8 R2 8 R3 7 CW 7 2S 7 Input 20 -> OP 9 R2 9 R3 6 CW 6 2S 6 Input 21 -> OP 10 R2 10 R3 7 CW 7 2S 7 Input 22 -> OP 11 R2 11 R3 7 CW 7 2S 7 Input 23 -> OP 12 R2 12 R3 8 CW 8 2S 8 Input 24 -> OP 13 R2 13 R3 6 CW 6 2S 6 Input 25 -> OP 14 R2 14 R3 7 CW 7 2S 7 Input 26 -> OP 15 R2 15 R3 7 CW 7 2S 7 Input 27 -> OP 16 R2 16 R3 8 CW 8 2S 8 Input 28 -> OP 17 R2 17 R3 7 CW 7 2S 7 Input 29 -> OP 18 R2 18 R3 8 CW 8 2S 8 Input 30 -> OP 19 R2 19 R3 8 CW 8 2S 8 Input 31 -> OP 20 R2 20 R3 9 CW 9 2S 9 Input 32 -> OP 21 R2 6 R3 6 CW 6 2S 6 Input 33 -> OP 7 R2 7 R3 7 CW 7 2S 7 Input 34 -> OP 8 R2 8 R3 7 CW 7 2S 7 Input 35 -> OP 9 R2 9 R3 8 CW 8 2S 8 Input 36 -> OP 10 R2 10 R3 7 CW 7 2S 7 Input 37 -> OP 11 R2 11 R3 8 CW 8 2S 8 Input 38 -> OP 12 R2 12 R3 8 CW 8 2S 8 Input 39 -> OP 13 R2 13 R3 9 CW 9 2S 9 Input 40 -> OP 14 R2 14 R3 7 CW 7 2S 7 Input 41 -> OP 15 R2 15 R3 8 CW 8 2S 8 Input 42 -> OP 16 R2 16 R3 8 CW 8 2S 8 Input 43 -> OP 17 R2 17 R3 9 CW 9 2S 9 Input 44 -> OP 18 R2 18 R3 8 CW 8 2S 8 Input 45 -> OP 19 R2 19 R3 9 CW 9 2S 9 Input 46 -> OP 20 R2 20 R3 9 CW 9 2S 9 Input 47 -> OP 21 R2 21 R3 10 CW 10 2S 10 Input 48 -> OP 22 R2 22 R3 7 CW 7 2S 7 Input 49 -> OP 23 R2 23 R3 8 CW 8 2S 8 Input 50 -> OP 24 R2 24 R3 8 CW 8 2S 8 Input 51 -> OP 25 R2 25 R3 9 CW 9 2S 9 Input 52 -> OP 26 R2 26 R3 8 CW 8 2S 8 Input 53 -> OP 27 R2 27 R3 9 CW 9 2S 9 Input 54 -> OP 28 R2 28 R3 9 CW 9 2S 9 Input 55 -> OP 29 R2 29 R3 10 CW 10 2S 10 Input 56 -> OP 30 R2 30 R3 8 CW 8 2S 8 Input 57 -> OP 31 R2 31 R3 9 CW 9 2S 9 Input 58 -> OP 32 R2 32 R3 9 CW 9 2S 9 Input 59 -> OP 33 R2 33 R3 10 CW 10 2S 10 Input 60 -> OP 34 R2 34 R3 9 CW 9 2S 9 Input 61 -> OP 35 R2 35 R3 10 CW 10 2S 10 Input 62 -> OP 36 R2 36 R3 10 CW 10 2S 10 Input 63 -> OP 37 R2 37 R3 11 CW 11 2S 11 Input 64 -> OP 38 R2 7 R3 7 CW 7 2S 7 Input 65 -> OP 8 R2 8 R3 8 CW 8 2S 8 Input 66 -> OP 9 R2 9 R3 8 CW 8 2S 8 Input 67 -> OP 10 R2 10 R3 9 CW 9 2S 9 Input 68 -> OP 11 R2 11 R3 8 CW 8 2S 8 Input 69 -> OP 12 R2 12 R3 9 CW 9 2S 9 Input 70 -> OP 13 R2 13 R3 9 CW 9 2S 9 Input 71 -> OP 14 R2 14 R3 10 CW 10 2S 10 Input 72 -> OP 15 R2 15 R3 8 CW 8 2S 8 Input 73 -> OP 16 R2 16 R3 9 CW 9 2S 9 Input 74 -> OP 17 R2 17 R3 9 CW 9 2S 9 Input 75 -> OP 18 R2 18 R3 10 CW 10 2S 10 Input 76 -> OP 19 R2 19 R3 9 CW 9 2S 9 Input 77 -> OP 20 R2 20 R3 10 CW 10 2S 10 Input 78 -> OP 21 R2 21 R3 10 CW 10 2S 10 Input 79 -> OP 22 R2 22 R3 11 CW 11 2S 11 Input 80 -> OP 23 R2 23 R3 8 CW 8 2S 8 Input 81 -> OP 24 R2 24 R3 9 CW 9 2S 9 Input 82 -> OP 25 R2 25 R3 9 CW 9 2S 9 Input 83 -> OP 26 R2 26 R3 10 CW 10 2S 10 Input 84 -> OP 27 R2 27 R3 9 CW 9 2S 9 Input 85 -> OP 28 R2 28 R3 10 CW 10 2S 10 Input 86 -> OP 29 R2 29 R3 10 CW 10 2S 10 Input 87 -> OP 30 R2 30 R3 11 CW 11 2S 11 Input 88 -> OP 31 R2 31 R3 9 CW 9 2S 9 Input 89 -> OP 32 R2 32 R3 10 CW 10 2S 10 Input 90 -> OP 33 R2 33 R3 10 CW 10 2S 10 Input 91 -> OP 34 R2 34 R3 11 CW 11 2S 11 Input 92 -> OP 35 R2 35 R3 10 CW 10 2S 10 Input 93 -> OP 36 R2 36 R3 11 CW 11 2S 11 Input 94 -> OP 37 R2 37 R3 11 CW 11 2S 11 Input 95 -> OP 38 R2 38 R3 12 CW 12 2S 12 Input 96 -> OP 39 R2 39 R3 8 CW 8 2S 8 Input 97 -> OP 40 R2 40 R3 9 CW 9 2S 9 Input 98 -> OP 41 R2 41 R3 9 CW 9 2S 9 Input 99 -> OP 42 R2 42 R3 10 CW 10 2S 10 Input 100 -> OP 43 R2 43 R3 9 CW 9 2S 9