题意:求出100!的各位数字和。


/*************************************************************************
> File Name: euler020.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月28日 星期三 11时46分46秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h> #define D_VALUE 1000
int32_t main() {
int32_t ans[2001] = {0};
ans[1] = ans[0] = 1;
for (int32_t i = 1 ; i <= 100 ; i++) {
for (int32_t j = 1 ; j <= ans[0] ; j++) {
ans[j] *= i;
}
for (int32_t j = 1 ; j <= ans[0] ; j++) {
if (ans[j] < D_VALUE) continue;
ans[j + 1] += ans[j] / D_VALUE;
ans[j] %= D_VALUE;
if (ans[0] == j) 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 20 Factorial digit sum( 大数乘法 )的更多相关文章

  1. Project Euler 16 Power digit sum( 大数乘法 )

    题意: 215 = 32768,而32768的各位数字之和是 3 + 2 + 7 + 6 + 8 = 26. 21000的各位数字之和是多少? 思路:大数乘法,计算 210 × 100 可加速计算,每 ...

  2. Project Euler Problem 16-Power digit sum

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

  3. Project Euler 56: Powerful digit sum

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

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

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

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

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

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

  8. Project Euler 92:Square digit chains C++

    A number chain is created by continuously adding the square of the digits in a number to form a new ...

  9. Project Euler 50 Consecutive prime sum

    题意: 素数41可以写成六个连续素数的和: 41 = 2 + 3 + 5 + 7 + 11 + 13 在小于一百的素数中,41能够被写成最多的连续素数的和. 在小于一千的素数中,953能够被写成最多的 ...

随机推荐

  1. 图论-BFS解无权有向图最短路径距离

    概述 本篇博客主要内容: 对广度优先搜索算法(Breadth-First-Search)进行介绍: 介绍用邻接表的存储结构实现一个图(附C++实现源代码): 介绍用BFS算法求解无权有向图(附C++实 ...

  2. Scala入门到精通——第一节 Scala语言初步

    本节主要内容 Scala简单介绍 为什么要学习Scala Scala语言初步 1. Scala简单介绍 Scala(Scala Language的简称)语言是一种能够执行于JVM和.Net平台之上的通 ...

  3. 转:APP测试总结

  4. C# List数据批量更新

    针对单条数据一般都是update语句直接更新 例如:update UserTable set UserName='小名'   where userid=xxx 但是如果是针对List数据组进行更新的话 ...

  5. 使用 AFNetworking的时候,怎样管理 session ID

    问: As the title implies, I am using AFNetworking in an iOS project in which the application talks to ...

  6. HDU-5310-Souvenir(C++ &amp;&amp; 简单数学题)

    Souvenir Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

  7. 再探Linux动态链接 -- 关于动态库的基础知识(Dynamic Linking on Linux Revisited)

      在近一段时间里,由于多次参与相关专业软件Linux运行环境建设,深感有必要将这些知识理一理,供往后参考. 编译时和运行时 纵观程序编译整个过程,细分可分为编译(Compiling,指的是语言到平台 ...

  8. ScrollViewer滚动究竟来触发载入数据的Behavior

    近期项目中遇到载入数据的性能问题, 原因是.net4.0的虚拟化支持不够完毕,有好多bug在4.5才修复. 我们仅仅能利用大家通用的做法来延迟载入数据: 每次载入固定少量的数据.当拖动究竟后.继续载入 ...

  9. c++11 实现半同步半异步线程池

    感受: 随着深入学习,现代c++给我带来越来越多的惊喜- c++真的变强大了. 半同步半异步线程池: 事实上非常好理解.分为三层 同步层:通过IO复用或者其它多线程多进程等不断的将待处理事件加入到队列 ...

  10. spring的bean管理(注解和配置文件混合使用)

    1.建三个类,在一个类中引用其他两个类 import javax.annotation.Resource; import org.springframework.beans.factory.annot ...