0
点赞
收藏
分享

微信扫一扫

Problem 48 Self powers (技巧)


Self powers


Problem 48


The series, 11 + 22 + 33 + ... + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.

Answer:

9110846700

Completed on Sun, 30 Oct 2016, 13:08


代码:


#include <iostream>
#include <cmath>
using namespace std;

long long power(int n)
{
long long ans = 1;
for (int i=1;i<=n;i++)
{
ans *= n;
ans %= 10000000000;
}
return ans;
}

int main()
{
long long sum = 0;
for (int i=1;i<=1000;i++)
{
sum += power(i);
sum %= 10000000000; //取模,只保留最低的10位
}
cout<<sum<<endl;
return 0;
}




举报

相关推荐

0 条评论