chibicitiberiu
New Member
How can I find the last digit of the following:
1^1 + 2^2 + 3^3 + 4^4 + ... + N^N, where N is a number specified in the input file.
I discovered that for n>=10, last digit of n^n = last digit of (n%10)^n.
But the limit for N is 2 billion, how will I calculate 9^2,000,000,000 to find it's last digit???
That number is way above long long data type.
How can I do this? Is there any formula I can use?
Ideas??
Note: For who doesn't know n^m means n at the m-th power.
1^1 + 2^2 + 3^3 + 4^4 + ... + N^N, where N is a number specified in the input file.
I discovered that for n>=10, last digit of n^n = last digit of (n%10)^n.
But the limit for N is 2 billion, how will I calculate 9^2,000,000,000 to find it's last digit???
That number is way above long long data type.
How can I do this? Is there any formula I can use?
Ideas??
Note: For who doesn't know n^m means n at the m-th power.