工学1号馆

home

Project Euler 48–Self powers

Wu Yudong    August 20, 2018     欧拉计划   540   

Self powers

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

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


自幂

十项的自幂级数求和为 11 + 22 + 33 + … + 1010 = 10405071317。

求如下一千项的自幂级数求和的最后10位数字:11 + 22 + 33 + … + 10001000

#include<stdio.h>
#include<math.h>

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位
	}
	printf("%lld\n", sum);
	return 0;
}

Answer:9110846700
Completed on Mon, 20 Aug 2018, 18:24

如果文章对您有帮助,欢迎点击下方按钮打赏作者

Comments

No comments yet.
To verify that you are human, please fill in "七"(required)