Medium 0 solved 0% acceptance

Digit Power Sum

Add each digit raised to its position from the left.

Problem

Number the digits of n from the left, starting at 1. Raise each digit to the power of its position and add the results. For 352 that is 3¹ + 5² + 2³. A zero digit adds 0.

Implement digit_power_sum(n).

Input

n: A positive integer.

Output

Return the sum of the powered digits.

Constraints

1 ≤ n ≤ 1,000,000,000

Examples

Example 1
Input:
n = 352

Expected output:
expected = 36
Input:
long long n = 352;

Expected output:
long long expected = 36;
Input:
long n = 352;

Expected output:
long expected = 36;

Explanation

3¹ + 5² + 2³ = 3 + 25 + 8 = 36.

Example 2
Input:
n = 89

Expected output:
expected = 89
Input:
long long n = 89;

Expected output:
long long expected = 89;
Input:
long n = 89;

Expected output:
long expected = 89;

Explanation

8¹ + 9² = 8 + 81 = 89, the number itself.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.