zoukankan      html  css  js  c++  java
  • Project Euler 20 Factorial digit sum( 大数乘法 )


    题意:求出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
    ",sum);
    	return 0;
    }
  • 相关阅读:
    React网络请求fetch之get请求
    英语学习
    人物传记
    四月
    启程
    情绪
    办公新址
    孩子大了
    幸福的生日
    hibernate---树状映射
  • 原文地址:https://www.cnblogs.com/WArobot/p/7089128.html
Copyright © 2011-2022 走看看