We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #30: Digit Nth powers
  4. Discussions

Project Euler #30: Digit Nth powers

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • Technophobe01
    1 year ago+ 1 comment

    My sense was to do the following.

    MIN = 2
    MAX = 1000000
    
    
    def compute(value):
        ans = sum(i for i in range(MIN, MAX)
                  if i == power_digit_sum(value, i))
        return str(ans)
    
    
    def power_digit_sum(value, n):
        return sum(int(c) ** value for c in str(n))
    
    
    if __name__ == "__main__":
        value = int(input())
        print(compute(value))
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy