Project Euler 16 Power digit sum( 大数乘法 )
题意:
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( 大数乘法 )的更多相关文章
- Project Euler Problem 16-Power digit sum
直接python搞过.没啥好办法.看了下别人做的,多数也是大数乘法搞过. 如果用大数做的话,c++写的话,fft优化大数乘法,然后快速幂一下就好了.
- Project Euler 20 Factorial digit sum( 大数乘法 )
题意:求出100!的各位数字和. /************************************************************************* > Fil ...
- Project Euler 56: Powerful digit sum
一个古戈尔也就是\(10^{100}\)是一个天文数字,一后面跟着一百个零.\(100^{100}\)更是难以想像的大,一后面跟着两百个零.但是尽管这个数字很大,它们各位数字的和却只等于一.考虑两个自 ...
- (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 ...
- project euler 16:Power digit sum
>>> sum([int(i) for i in str(2**1000)]) 1366 >>>
- Project Euler 48 Self powers( 大数求余 )
题意: 项的自幂级数求和为 11 + 22 + 33 + - + 1010 = 10405071317. 求如下一千项的自幂级数求和的最后10位数字:11 + 22 + 33 + - + 100010 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Win10 中修改cmd字体引发的问题
Win10 中修改cmd字体引发的问题 学习了:https://www.cnblogs.com/Diryboy/archive/2015/12/05/Use-Consolas-MSYaHei-in-C ...
- android中常见的内存泄漏和解决的方法
android中的内存溢出预计大多数人在写代码的时候都出现过,事实上突然认为工作一年和工作三年的差别是什么呢.事实上干的工作或许都一样,产品汪看到的结果也都一样,那差别就是速度和质量了. 写在前面的一 ...
- BIEE11G Rpd合并
Rpd合并 如图,合并两个rpd须要用三个rpd文件来操作.一个是blank.rpd.这是一个空白rpd,在biee合并的时候作为"原始主资料档案库":另一个是modified.R ...
- Android中验证输入是否为汉字及手机号,邮箱验证,IP地址可用port号验证
1,验证是否为汉字 // 验证昵称 private boolean verifyNickname() { String nickname = edt_username.getText().toStri ...
- js自定义回调函数
JavaScript允许开发人员像传递任何类型的数据一样传递函数,也就是说,函数也是一种数据类型,通过typeof就知道. 例子1: var CallbackFun = function(){ t ...
- androidstudio集成ijkplayer教程
介绍 ijkplayer是一款非常火的开源视频播放器,android和IOS通用.关于怎么编译怎么导入android Studio中自己的项目,其中坑很多,本篇记录下自己的操作记录.ijkplay ...
- hdoj--1083--Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 【POI 2007】 山峰和山谷
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1102 [算法] 广度优先搜索 [代码] #include<bits/stdc+ ...
- Asura监控---AsuraMonitor,阿修罗监控开源
阿修罗Monitor是一个功能强大.灵活的监控系统. 系统安装简单,配置简单,相比zabbix, nagios,cacti,小米监控等都使用相当简单.只需要会写脚本,语言不限就可以实现任意监控需求. ...
- ansible usually
链接地址:https://my.oschina.net/kangvcar/blog/1830155