fork download
  1. using System;
  2. using System.Collections.Generic;
  3. public class Test
  4. {
  5. class Program
  6. {
  7. static int poteguj(int podst, int wyk)
  8. {
  9. int[] do_rozwazenia = new int[10];
  10. int pow = 1;
  11. for (int i = 0; i < 10; i++)
  12. {
  13. pow *= podst;
  14. for (int j = 0; j < i; j++)
  15. if (do_rozwazenia[j] == (pow % 10))
  16. return do_rozwazenia[(wyk - 1) % i];
  17. do_rozwazenia[i] = pow % 10;
  18. }
  19. return -1;
  20. }
  21.  
  22.  
  23. public static void Main()
  24. {
  25. Convert.ToInt32(Console.ReadLine()); //to jest całkiem niepotrzebne, błąd w założeniu zadania
  26. string temp_values = Console.ReadLine();
  27. while(!String.IsNullOrEmpty(temp_values))
  28. {
  29. string[] tv = temp_values.Split();
  30. if (tv.Length!=2) continue;
  31. int podstawa = Convert.ToInt32(tv[0]);
  32. int potega = Convert.ToInt32(tv[1]);
  33. Console.WriteLine(poteguj(podstawa, potega));
  34. temp_values = Console.ReadLine();
  35. }
  36. }
  37. }
  38. }
Success #stdin #stdout 0.01s 131648KB
stdin
2
2 2
12 8
9 11
stdout
4
6
9