Editorial for MWC '15 #1 P5: Love Guru
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
First of all, we should note that is just taking the unit digit (with the special case described for ). The unit digits of the powers of a number follows a pattern. Additionally, only the unit digit of the base of the power is relevant, meaning is equivalent to . Either storing the number cycles or modding the power by 4 (the LCM of the cycle lengths of the digits) is sufficient to pass.
Time complexity: where is the total number of letters in both names.
Comments