Problem 16

Problem 16

pow(2, 15) = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.2的15次方等于32768,而这些数字(3+2+7+6+8)的和为26What is the sum of the digits of the number pow(2, 1000)?2的1000次方的位数之和为多少?
import math

power = math.pow(2, 1000)
sum_of_digits = 0
with open(‘power_of_two.txt‘, ‘w‘) as f:
    print(‘%d‘ % power, file=f)
with open(‘power_of_two.txt‘) as f:
    for line in f:
        for c in line:
            try:
                sum_of_digits += int(c)
            except:
                pass

print(sum_of_digits)


原文地址:https://www.cnblogs.com/noonjuan/p/10962302.html

时间: 2024-08-09 05:43:10

Problem 16的相关文章

欧拉计划(python) problem 16

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? Answer: 1366 Completed on Tue, 27 Jan 2015, 04:14 k=1000 temp=1; for i in range(1,k+1): temp*=2 temp=str(te

Project Euler: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 the number 21000? #include <iostream> #include <string> using namespace std; int main() { string s = "1"; for (int i = 1; i <= 1000;

水题 HDOJ 4716 A Computer Graphics Problem

题目传送门 1 /* 2 水题:看见x是十的倍数就简单了 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const int MAXN = 1e4 + 10; 13

LeetCode All in One 题目汇总

228 Summary Ranges 21.10% Easy 227 Basic Calculator II 18.00% Medium 226 Invert Binary Tree 35.40% Easy 225 Implement Stack using Queues 29.60% Medium 224 Basic Calculator 15.80% Medium 223 Rectangle Area 25.60% Easy 222 Count Complete Tree Nodes 19.

You Can Do Research Too

You Can Do Research Too I was recently discussing gatekeeping and the process of getting started in CS research with a close friend. I feel compelled to offer a note. As a practicing academic researcher, I’m personally thrilled by the degree of excit

面试中常见算法1

Problem 1 : Is it a loop ? (判断链表是否有环?) Assume that wehave a head pointer to a link-list. Also assumethat we know the list is single-linked. Can you come up an algorithm to checkwhether this link list includes a loop by using O(n) time and O(1) space

CodeForces 16A Flag

题目链接:http://codeforces.com/problemset/problem/16/A 题意:给出n行m列一个图案,要求每行必须一样,相邻行不能相同. 代码: int main() { int n,m;char t=0,t1,a[106],ff=0; cin>>n>>m; for(int i=0;i<n;i++) { scanf("%s",a); t=a[0]; if(t1==t&&i!=0) { ff=1; } for(in

linux下包管理器

一.操作linux发型版本的包管理器 此小结摘抄:https://www.cnblogs.com/linuxprobe/p/5883783.html   在 linux 中,包管理器非常重要,了解如何使用多种包管理器可以让你像一个高手一样活得很舒适,从在仓库下载软件.安装软件,到更新软件.处理依赖和删除软件是非常重要的,这也是Linux 系统管理的一个重要部分. debian派系   dpkg 是 Debian Linux 家族的基础包管理系统,它用于安装.删除.存储和提供deb包的信息.这是一

Bubblesort and oblivious

Problem 12. (Difficulty 2) Bubblesort and oblivious merge-sort each give a sequence ofcompare-exchange operations which sorts any array A[0..3]. Write down both sequences.Problem 13. (Difficulty 4) For n distinct elements x1, x2, . . . , xn with posi