Problem 48 Self powers (技巧)

来源:互联网 发布:库房库存数据分析 编辑:程序博客网 时间:2024/05/21 09:33

Self powers

Problem 48

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

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


Answer:
9110846700Completed 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;}



2 0