Explanation needed

need detailed explanation on this topic
start 10 mins i didnt understand how A and B are computed so rest of the part was no use

@PoojaSingh22
i am supposing you know the topics like modulo properties and fermat little theorem.
so, lets suppose A=153 then
(i) 153%6 = 3
(ii) (100%6 + 50%6 + 3%6)%6 = 3, by breaking the number into ones, tens, hundred…
Since here A was small so it was possible to calculate directly but if A is 10^10000 then it will not be possible to store and find it in long long int also.
So for storing them we will use string and then convert that string into integer by taking modulo at every possible step.
Here based on above explanation, you can dry run and understand the below code easily for converting the string input A and B into integer

ll convert(string num, ll mod) {
    ll n = num.size();
    ll res =0;

    for(int i=0; i<n; i++) {
        res = ((res*10)%mod + num[i]-'0')%mod;   //just taking every digit and adding to result,
    }

    return res;
}

So after converting that you just have to find A^b % p, as given in the question which can also easily done with the help of fast exponentiation.

@PoojaSingh22
If you don’t know about fermat little theorem then you can google about it, also the explanation given in video is enough and only result is required to be remembered.