36 lines
670 B
C++
36 lines
670 B
C++
/** The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
|
|
Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000. */
|
|
|
|
#include "0.hpp"
|
|
#include "lib/lint.cpp"
|
|
|
|
#define _max 1000
|
|
#define _mod 10000000000
|
|
#define _array 10
|
|
|
|
uu pow(uu a, uu b, uu mod = _mod)
|
|
{
|
|
int bi[_array] = {0};
|
|
for(int i = 0; i < _array; i++) {
|
|
bi[i] = b % 2;
|
|
b /= 2;
|
|
}
|
|
uu out = 1;
|
|
for(int i = _array - 1; i >= 0; i--) {
|
|
out = (out % mod) * out % mod;
|
|
if(bi[i] == 1) out = (out * a) % mod;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
uu sum = 0;
|
|
for(uu i = 1; i <= _max; i++) {
|
|
sum += pow(i, i);
|
|
sum = sum % _mod;
|
|
}
|
|
cout << sum << endl;
|
|
return 0;
|
|
}
|