zoukankan      html  css  js  c++  java
  • [Project Euler] Problem 56

    Problem Description

    A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

    Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?

    Python

    Of course python, here is the code:

    def Power(a, b) :
        result = 1
        for i in xrange(b):
            result = result * a    
        return result
    
    def GetSum(num) :
        strNum = str(num)
        result = 0;
        for index in xrange(len(strNum)) :
            result = result + int(strNum[index])
        return result
    
    def Problem_56() :
        maxNum = 0
        maxA =0;
        maxB =0;
        for a in xrange(1, 100):
            for b in xrange(1, 100) :
                temp = GetSum(Power(a, b))
                # print "a=%d, b=%d temp=%d" % (a, b, temp)
                if(temp > maxNum) :
                    maxNum = temp
                    maxA = a
                    maxB = b
        print "%d^%d = %d" % (maxA, maxB, maxNum)
    
    Problem_56()

    Thi problem is easy, brute force is needed.

  • 相关阅读:
    笛卡尔树学习笔记
    图论基础(自认为很全)
    我的博客在这里
    C++学习资料
    test
    个人介绍
    CF1153F Serval and Bonus Problem
    【ZJOI2020】抽卡
    【LOJ】小 Q 的序列
    我的个人博客:https://xyix.github.io
  • 原文地址:https://www.cnblogs.com/quark/p/2621099.html
Copyright © 2011-2022 走看看