fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3. public class Test
  4. {
  5. class Program
  6. {
  7. public static int determine_value_at_position_of_an_array(List<int> arr, int potega)
  8. {
  9. int counter = 1;
  10. int counter_2 = 0;
  11. int current_value = 0;
  12.  
  13. for (; counter<= potega; counter++)
  14. {
  15. current_value = arr[counter_2];
  16. if (counter_2==arr.Count-1)
  17. {
  18. counter_2 = 0;
  19. }
  20. else
  21. {
  22. counter_2++;
  23. }
  24. }
  25.  
  26. return current_value;
  27. }
  28. public static int get_last_number(int n)
  29. {
  30. string temp = Convert.ToString(n);
  31. char tempo = Convert.ToChar((temp[temp.Length - 1]));
  32. int result = (int)Char.GetNumericValue(tempo);
  33. return result;
  34. }
  35. public static List<int> Pattern_Finder(int podstawa)
  36. {
  37. List<int> sequence = new List<int>();
  38.  
  39. int goal = (get_last_number(podstawa));
  40. sequence.Add(goal);
  41.  
  42. int startowa_potega = 2;
  43. int temp = 0;
  44.  
  45. while (true)
  46. {
  47. temp = pow(podstawa, startowa_potega);
  48. if (get_last_number(temp) == goal)
  49. {
  50. break;
  51. }
  52. startowa_potega++;
  53. sequence.Add(get_last_number(temp));
  54. }
  55.  
  56. return sequence;
  57. }
  58.  
  59. public static int pow(int podstawa, int potega)
  60. {
  61. int result = 1;
  62. while (potega > 0)
  63. {
  64. result *= podstawa;
  65. potega--;
  66. }
  67. return result;
  68. }
  69.  
  70. public static int Answer_Finder(int podstawa, int potega)
  71. {
  72. switch (podstawa)
  73. {
  74. case 0:
  75. return 1;
  76. case 1:
  77. return 1;
  78. }
  79.  
  80. List<int> sequence = Pattern_Finder(podstawa);
  81. int result = determine_value_at_position_of_an_array(sequence, potega);
  82. return result;
  83. }
  84.  
  85. public static void Main()
  86. {
  87. int n = Convert.ToInt32(Console.ReadLine());
  88. while (n > 0)
  89. {
  90. string[] temp_values = Console.ReadLine().Split(' ');
  91. int podstawa = Convert.ToInt32(temp_values[0]);
  92. int potega = Convert.ToInt32(temp_values[1]);
  93. Console.WriteLine(Answer_Finder(podstawa, potega));
  94. }
  95. }
  96. }
  97. }
Runtime error #stdin #stdout #stderr 0s 135168KB
stdin
2
12 8
9 11
stdout
6
9
stderr
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at Test+Program.Main () [0x00015] in <aadb5cd4cd0b40dfb6d217f3caa1c3e4>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at Test+Program.Main () [0x00015] in <aadb5cd4cd0b40dfb6d217f3caa1c3e4>:0