Project Euler Problem 16 Power digit sum
来源:互联网 发布:挖矿软件是什么 编辑:程序博客网 时间:2024/05/17 09:10
Power digit sum
Problem 16
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
C++:
#include <iostream>#include <cstring>using namespace std;const int MAXN = 1000;int result[MAXN+1];int power(int a, int n){ int digits, j; memset(result, 0, sizeof(result)); result[0] = a; digits = 1; for(int i=2; i<=n; i++) { int carry = 0; for(j=0; j<digits; j++) result[j] *= a; for(j=0; j<=digits; j++) { result[j] += carry; carry = result[j] / 10; result[j] %= 10; } digits = j; } return digits;}int main(){ int n, digits; while(cin >> n) { digits = power(2, n); int sum = 0; for(int i=0; i<=digits; i++) sum += result[i]; cout << sum << endl; } return 0;}
1 0
- Project Euler:Problem 16 Power digit sum
- Project Euler Problem 16 Power digit sum
- Project Euler 16: Power digit sum.
- Project Euler 题解 #16 Power digit sum
- 16 Power digit sum - Project Euler
- project euler 16 Power digit sum
- Project Euler:Problem 20 Factorial digit sum
- Project Euler:Problem 56 Powerful digit sum
- Project Euler Problem 20 Factorial digit sum
- Problem 16:Power digit sum
- Problem 16:Power digit sum
- Problem 16 Power digit sum
- Matlab 编程 Project Euler Problem 20 Factorial digit sum
- projecteuler---->problem=16----Power digit sum
- ProjectEuler-Problem 16-Power digit sum
- Project Euler 题解 #20 Factorial digit sum
- 20 Factorial digit sum - Project Euler
- project euler 20 Factorial digit sum
- leetcode 3. Longest Substring Without Repeating Characters
- uva620
- 证明在含环的链表中,快慢指针最终会相遇。
- XML配置文件的解析 写入
- 写于三月的反思与总结
- Project Euler Problem 16 Power digit sum
- C++求最大公约数的三种方法
- CodeForces
- angr 的中文说明文档
- WEB开发性能优化--核心定义介绍篇(1)
- 387. First Unique Character in a String (C++)
- 数值分析读书笔记(1)导论
- 观察者模式
- html/css知识点问题及答案汇总