Mittel 0 gelöst 0% Erfolgsquote

Digit Power Sum

Add each digit raised to its position from the left.

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.

Einschränkungen

1 ≤ n ≤ 1,000,000,000

Beispiele

Beispiel 1
Eingabe:
n = 352

Erwartete Ausgabe:
expected = 36
Eingabe:
long long n = 352;

Erwartete Ausgabe:
long long expected = 36;
Eingabe:
long n = 352;

Erwartete Ausgabe:
long expected = 36;

Erläuterung

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

Beispiel 2
Eingabe:
n = 89

Erwartete Ausgabe:
expected = 89
Eingabe:
long long n = 89;

Erwartete Ausgabe:
long long expected = 89;
Eingabe:
long n = 89;

Erwartete Ausgabe:
long expected = 89;

Erläuterung

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

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.