Project Euler 16 Power digit sum( 大数乘法 )
题意:
215 = 32768,而32768的各位数字之和是 3 + 2 + 7 + 6 + 8 = 26。
21000的各位数字之和是多少?
思路:大数乘法,计算 210 × 100 可加速计算,每次超过1000进位
/*************************************************************************
> File Name: euler016.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月27日 星期二 20时41分24秒
************************************************************************/
#include <stdio.h>
#include <inttypes.h>
#define D_VALUE 1000
int32_t main() {
int32_t ans[1001] = {0};
ans[0] = ans[1] = 1; // ans[0] 记录位数
for (int32_t i = 0 ; i < 100 ; i++) {
for (int32_t j = 1 ; j <= ans[0] ; j++) {
ans[j] *= 1024;
}
for (int32_t j = 1 ; j <= ans[0] ; j++) {
if (ans[j] >= D_VALUE) {
ans[j + 1] += ans[j] / D_VALUE;
ans[j] %= D_VALUE;
if (j == ans[0]) ans[0]++;
}
}
}
int32_t sum = 0;
for (int32_t i = 1 ; i <= ans[0] ; i++) {
while (ans[i]) {
sum += ans[i] % 10;
ans[i] /= 10;
}
}
printf("%d\n",sum);
return 0;
}
Project Euler 16 Power digit sum( 大数乘法 )的更多相关文章
- Project Euler Problem 16-Power digit sum
直接python搞过.没啥好办法.看了下别人做的,多数也是大数乘法搞过. 如果用大数做的话,c++写的话,fft优化大数乘法,然后快速幂一下就好了.
- Project Euler 20 Factorial digit sum( 大数乘法 )
题意:求出100!的各位数字和. /************************************************************************* > Fil ...
- Project Euler 56: Powerful digit sum
一个古戈尔也就是\(10^{100}\)是一个天文数字,一后面跟着一百个零.\(100^{100}\)更是难以想像的大,一后面跟着两百个零.但是尽管这个数字很大,它们各位数字的和却只等于一.考虑两个自 ...
- (Problem 16)Power digit sum
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...
- project euler 16:Power digit sum
>>> sum([int(i) for i in str(2**1000)]) 1366 >>>
- Project Euler 48 Self powers( 大数求余 )
题意: 项的自幂级数求和为 11 + 22 + 33 + - + 1010 = 10405071317. 求如下一千项的自幂级数求和的最后10位数字:11 + 22 + 33 + - + 100010 ...
- Project Euler 83:Path sum: four ways 路径和:4个方向
Path sum: four ways NOTE: This problem is a significantly more challenging version of Problem 81. In ...
- Project Euler 82:Path sum: three ways 路径和:3个方向
Path sum: three ways NOTE: This problem is a more challenging version of Problem 81. The minimal pat ...
- Project Euler 81:Path sum: two ways 路径和:两个方向
Path sum: two ways In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom ...
随机推荐
- [bzoj1861][Zjoi2006]Book 书架_非旋转Treap
Book 书架 bzoj-1861 Zjoi-2006 题目大意:给你一个序列,支持:将指定编号的元素抽出,放到序列顶(底):将指定编号元素左右篡位:查询指定编号元素位置:查询指定数量位置元素编号. ...
- 开源分布式MySQL中间件探究与应用 dba+
- Amoeba for MySQL 中间件
来源:http://docs.hexnova.com/amoeba/ Amoeba for MySQL致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当query 路 ...
- POJ 1654
不知 是怎么看出的精度不够,吸经验吧. #include <iostream> #include <cstdio> #include <cstring> #incl ...
- HDU 2255 奔小康赚大钱 KM算法题解
KM算法求的是完备匹配下的最大权匹配,是Hungary算法的进一步,由于Hungary算法是最大匹配的算法,不带权. 经典算法,想不出来的了,要參考别人的.然后消化吸收吧. 由于真的非常复杂的算法. ...
- Linux下安装JRE和Eclipse IDE for C/C++ Developers
Linux32位,下载eclipse-cpp-luna-R-linux-gtk.tar.gz和jre-8u11-linux-i586.rpm 放到家文件夹中. http://www.eclipse. ...
- Web进行压力测试的小工具
在Linux下对Web进行压力测试的小工具有很多,比较出名的有AB.虽然AB可以运行在windows下,但对于想简单界面操作的朋友有点不太习惯.其实vs.net也提供压力测试功能但显然显得太重了,在测 ...
- tinyxml使用
1.下载地址 http://sourceforge.net/projects/tinyxml/ 2.tinyxml不仅支持Linux编译,同时也支持windows下编译,由于tinyxml仅有6个文件 ...
- elasticsear+kibana+logstash 优化
##关于s2安装cerebro来可视化集群管理##### https://blog.csdn.net/RWSLR6/article/details/79648767 https://github.co ...
- JavaScrip——插入地图
具体操作步骤:1.百度搜索:百度地图生成器 2.打开第一个,复制网址http://api.map.baidu.com/lbsapi/creatmap/index.html,打开3.页面显示为 4.根据 ...