题意:求出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. 手动编译java的package问题,及演示继承的基本实现

    不用IDE,而直接用命令编译JAVA包,仔细看了下,作一个记录. 以下的URL值得收藏. http://www.aiuxian.com/article/p-2115485.html http://ww ...

  2. Spring MVC-表单(Form)标签-密码框(Password)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_password.htm 说明:示例基于Spring MVC 4.1.6. 以下示 ...

  3. 基于ffmpeg和libvlc的视频剪辑、播放器

    以前研究的时候,写过一个简单的基于VLC的视频播放器.后来因为各种项目,有时为了方便测试,等各种原因,陆续加了一些功能,现在集成了视频播放.视频加减速.视频剪切,视频合并(增加中)等功能在一起.有时候 ...

  4. 关于在linux下出现stdio.h文件不存在等gcc标准库不能找到的解决的方法

    首先说明一下我的系统配置:ubuntu 12.04     gcc 4.6.3 有几天没有使用ubuntu了,今天拿出来编程序,刚開始编译一个uboot1.1.6的代码.出现了stdio.h:没有那么 ...

  5. PostgreSQL sum typecasting as a bigint

    https://stackoverflow.com/questions/20203081/postgresql-sum-typecasting-as-a-bigint Question: I am d ...

  6. iOS中基于 Socket 的 C/S 结构网络通信(中)

    结合上一篇的知识.接下来将介绍基于 TCP 协议的 Socket  编程.因为 Socket 须要有client和服务端,那么如今实现的是关于服务端的简单程序.服务端採用的是CFStream 类来实现 ...

  7. 《Java程序设计》第16周周五:数据库连接 与 随机数的使用

    第一部分:实验项目 项目二:数据库初步. 目的:了解Java连接数据库的步骤与方法.以及MySQL数据库的安装与使用. 目标: (1)在机房安装上MySQL数据库. 安装成功 MySQL数据库 (2) ...

  8. 常用框架(一):spring+springMvc+mybatis+maven

    项目说明: (1) 本例采用 maven web 工程做例子讲解 (2) 利用mybaits 提供的代码生成工具自动生成代码(dao接口,sql mapper映射文件,pojo数据库映射类) (3) ...

  9. 怎样在Android.mk上加宏定义【转】

    本文转载自:http://blog.csdn.net/ttxgz/article/details/7591282 很简单, LOCAL_CFLAGS += -DWHATEVERDEFINE 就可以了

  10. identity in sql server 批量插入history

    https://stackoverflow.com/questions/1920558/what-is-the-difference-between-scope-identity-identity-i ...