题意:

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( 大数乘法 )的更多相关文章

  1. Project Euler Problem 16-Power digit sum

    直接python搞过.没啥好办法.看了下别人做的,多数也是大数乘法搞过. 如果用大数做的话,c++写的话,fft优化大数乘法,然后快速幂一下就好了.

  2. Project Euler 20 Factorial digit sum( 大数乘法 )

    题意:求出100!的各位数字和. /************************************************************************* > Fil ...

  3. Project Euler 56: Powerful digit sum

    一个古戈尔也就是\(10^{100}\)是一个天文数字,一后面跟着一百个零.\(100^{100}\)更是难以想像的大,一后面跟着两百个零.但是尽管这个数字很大,它们各位数字的和却只等于一.考虑两个自 ...

  4. (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 ...

  5. project euler 16:Power digit sum

    >>> sum([int(i) for i in str(2**1000)]) 1366 >>>

  6. Project Euler 48 Self powers( 大数求余 )

    题意: 项的自幂级数求和为 11 + 22 + 33 + - + 1010 = 10405071317. 求如下一千项的自幂级数求和的最后10位数字:11 + 22 + 33 + - + 100010 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. GetBulkRequest PDU的应用

    http://blog.csdn.net/wenph2008/article/details/16821617

  2. Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容

    Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容 当Git无法自动合并分支时,就必须首先解 ...

  3. String 经常用法最优算法实现总结 (一)

    <pre name="code" class="java"><span style="font-family: Arial, Hel ...

  4. HDU 5187

    超简单的公式题(2^n-2).不过,要过可不容易,因为会爆64位,所以,可以使用快速乘法. #include <iostream> #include <cstdio> #inc ...

  5. 搭建单机CDH环境,并更新spark环境

    搭建单机CDH环境,并更新spark环境 1,安装VMWare Player,http://dlsw.baidu.com/sw-search-sp/soft/90/13927/VMware_playe ...

  6. 1016. Phone Bills (25)——PAT (Advanced Level) Practise

    题目信息: 1016. Phone Bills (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A l ...

  7. 关于Linux静态库和动态库的分析

    关于Linux静态库和动态库的分析 关于Linux静态库和动态库的分析 1.什么是库 在windows平台和linux平台下都大量存在着库. 本质上来说库是一种可运行代码的二进制形式.能够被操作系统加 ...

  8. 【小超_Android】GitHub源码项目整理,希望对大家有帮助

    收集的经常使用Github上比較优秀的项目,希望对大家日常开发有所帮助: AndroidSlidingMenu   https://github.com/jfeinstein10/SlidingMen ...

  9. luogu1120 小木棍【数据加强版】 暴力剪枝

    题目大意 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50.现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度.给出每段小木棍的长度,编程帮 ...

  10. 获取id 获取当前点击元素节点的任意 属性

    <a id="haveproces" onclick="fnProces(event)" dataid="{{x.id}}" clas ...