Project Euler #30: Digit Nth powers

  • + 0 comments

    This code workes well using python 3

    def main():
        n = int(input())
        total_sum = 0
    
        for i in range(2, 10**6):
            temp = i
            sum1 = 0
    
            while temp > 0:
                a = temp % 10
                sum1 += a**n
                temp = temp // 10
    
            if sum1 == i:
                total_sum += sum1
    
        print(total_sum)
    
    if __name__ == "__main__":
        main()