题意:求出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. EXTJS之DATA PROXY READER

    这是不依赖于STORE的读取.我测试了很久,原来在新版本的EXTJS里.modelmanager.getmodel之类的不用了. 更改为静态的LOAD办法. <!DOCTYPE html> ...

  2. [bzoj4864][BeiJing2017Wc]神秘物质_非旋转Treap

    神秘物质 bzoj-4864 BeiJing-2017-Wc 题目大意:给定一个长度为n的序列,支持插入,将相邻两个元素合并并在该位置生成一个指定权值的元素:查询:区间内的任意一段子区间的最大值减最小 ...

  3. codevs——T2894 Txx考试

    http://codevs.cn/problem/2894/  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descri ...

  4. 继续过Hard题目

    接上一篇:http://www.cnblogs.com/charlesblc/p/6283064.html 继续过Hard模式的题目吧.   # Title Editorial Acceptance ...

  5. 10317 Fans of Footbal Teams

    10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description ...

  6. 关于Spring中的<context:annotation-config/>配置作用

    转自:https://www.cnblogs.com/iuranus/archive/2012/07/19/2599084.html 当我们需要使用BeanPostProcessor时,直接在Spri ...

  7. weixin js接口

    <!DOCTYPE HTML><html><head> <meta http-equiv="content-type" content=& ...

  8. [牛客挑战赛 30D] 小A的昆特牌 解题报告 (组合数学)

    interlinkage: https://ac.nowcoder.com/acm/contest/375/D description: solution: 我们枚举步兵的数量$x$,还剩下$S-x$ ...

  9. UVA-12578 10:6:2 计算几何 模拟

    题面 题意:给你一块长方形,告诉你长:宽=10:6 里面有一个圆,长:半径=5:1,给你长方形的长,求圆的面积和剩余部分的面积 题解:直接模拟输出就好 #include<bits/stdc++. ...

  10. Laravel-查询作用域

    Laravel-查询作用域 标签(空格分隔): php, laravel 全局作用域 ## 编写全局作用域 ## 编写全局作用域很简单.定义一个实现 Illuminate\Database\Eloqu ...