using System; using System.Collections.Generic; public class Test { class Program { static int poteguj(int podst, int wyk) { int[] do_rozwazenia = new int[10]; int pow = 1; for (int i = 0; i < 10; i++) { pow *= podst; for (int j = 0; j < i; j++) if (do_rozwazenia[j] == (pow % 10)) return do_rozwazenia[(wyk - 1) % i]; do_rozwazenia[i] = pow % 10; } return -1; } public static void Main() { Convert.ToInt32(Console.ReadLine()); //to jest całkiem niepotrzebne, błąd w założeniu zadania string temp_values = Console.ReadLine(); while(!String.IsNullOrEmpty(temp_values)) { string[] tv = temp_values.Split(); if (tv.Length!=2) continue; int podstawa = Convert.ToInt32(tv[0]); int potega = Convert.ToInt32(tv[1]); Console.WriteLine(poteguj(podstawa, potega)); temp_values = Console.ReadLine(); } } } }