Skip to content

Instantly share code, notes, and snippets.

@Sephiroth-XIII
Last active August 29, 2015 14:13
Show Gist options
  • Save Sephiroth-XIII/ce18253f8e0ce4ce018b to your computer and use it in GitHub Desktop.
Save Sephiroth-XIII/ce18253f8e0ce4ce018b to your computer and use it in GitHub Desktop.
/*
The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
*/
#include <iostream>
#include <cmath>
using namespace std;
unsigned long power(int n)
{
unsigned long a=1;
for (int i = 0; i < n; ++i)
{
a=(a*n)%(unsigned long)pow(10,10);
}
return a;
}
int main()
{
unsigned long sum=0;
for (int i = 1; i <=1000 ; ++i)
{
sum=(sum+power(i))%(unsigned long)pow(10,10);
}
cout<<sum<<"\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment