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 ...
随机推荐
- navicat 为表添加索引
navicat 为表添加索引 分析常用的查询场景,为字段添加索引,增加查询速度. 可以添加单列索引,可以添加联合索引. 右键,设计表中可以查看和添加修改索引! 索引一定要根据常用的查询场景进行添加! ...
- [bzoj3123][Sdoi2013]森林_主席树_启发式合并
森林 bzoj-3123 Sdoi-2013 题目大意:给定一片共n个点的森林,T个操作,支持:连接两个不在一棵树上的两个点:查询一棵树上路径k小值. 注释:$1\le n,T \le 8\cdot ...
- TCP/IP解析(一):TCP/IP的工作方式
本文包括下面内容: 1.TCP/IP协议系统 2.OSI模型 3.数据包 4.TCP/IP的交互方式 1.TCP/IP模型的协议层 分为四层: 网络訪问层:提供与物理网络连接的接口.依据硬件的物理地址 ...
- android小技巧:在activity中实现与绑定的fragment的回调
看到标题你可能会想是一个多么高大上的技巧呢?事实上非常一般就是自己定义回调函数. 首先我们知道activity之间的数据传递有几种方式: 一是startActivityForResut()启动一个ac ...
- 我的红外arduino链接,!!!!
点击打开链接http://blog.csdn.net/g1342522389/article/details/46272473 一定要赞,小编非常辛苦.
- How to fix yum errors on CentOS, RHEL or Fedora
Yum is a package management tool for installing, updating and removing rpm packages on RedHat-based ...
- 在Windows 8.1系统上配置免安装版mysql-5.6.21-winx64
1.到官网上下载MySQL 下载地址为:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21-winx64.zip 2.解压文件到D盘 当然你可以 ...
- oc08--局部变量,全局变量,函数方法的区别
// // main.m // 局部变量和全局变量以及成员变量的区别 #import <Foundation/Foundation.h> @interface Person : NSObj ...
- c22---枚举
// // main.c // 枚举基本概念 #include <stdio.h> int main(int argc, const char * argv[]) { // int sex ...
- Springboot使用AOP实现统一处理Web请求日志
1.要使我们自定义的记录日志能够打印出来,我们需要先排除springboot默认的记录日志,添加如下的设置 2.新建 resources/log4j.properties 我的设置为: # LOG4J ...