博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Project Euler Problem 48: Self powers
阅读量:7119 次
发布时间:2019-06-28

本文共 837 字,大约阅读时间需要 2 分钟。

Problem 48

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

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

C++:

#include 
using namespace std;typedef unsigned long long ULL;const ULL DIGITS10 = 10000000000;// 模幂函数ULL powermod(__uint128_t a, int n, ULL m){ __uint128_t res = 1L; while(n) { if(n & 1L) { res *= a; res %= m; } a *= a; a %= m; n >>= 1; } return (ULL)res;}int main(){ long n; ULL ans; while(cin >> n) { ans = 0; for(int i=1; i<=n; i++) { ans += powermod(i, i, DIGITS10); ans %= DIGITS10; } cout << ans << endl; } return 0;}

Python:

print(sum([(x**x)%(10**10) for x in range(1,1001)])%(10**10))

转载于:https://www.cnblogs.com/tigerisland/p/7564037.html

你可能感兴趣的文章
CoffeeScript简介 <一>
查看>>
jQuery Easy UI Panel(面板)组件
查看>>
SharePoint2010升级到SharePoint2013操作手册
查看>>
WebService到底是什么?
查看>>
C++ 著名程序库 概览
查看>>
kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)
查看>>
springmvc返回值、数据写到页面、表单提交、ajax、重定向
查看>>
制作可以 SSH 登录的 Docker 镜像
查看>>
PHP
查看>>
struts2 helloworld
查看>>
http://www.ibm.com/developerworks/cn/java/j-lo-hotswapcls/
查看>>
王垠:对博士学位说永别
查看>>
本来连学计算机的都不是,怎么却读了计算机研究生
查看>>
LeetCode-326. Power of Three
查看>>
HDU 5305 Friends dfs
查看>>
【Swift】iOS UICollectionView 计算 Cell 大小的陷阱
查看>>
Windows Azure 入门系列课程Windows Azure 入门系列课程
查看>>
VK Cup 2016 - Round 1 (Div. 2 Edition) A. Bear and Reverse Radewoosh 水题
查看>>
成都Uber优步司机奖励政策(3月31日)
查看>>
jquery通过ajax方法获取json数据不执行success
查看>>