모든 챌린지
보통 0명 해결 정답률 0%

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.

제약 조건

1 ≤ n ≤ 1,000,000,000

예시

예시 1
입력:
n = 352

예상 출력:
expected = 36
입력:
long long n = 352;

예상 출력:
long long expected = 36;
입력:
long n = 352;

예상 출력:
long expected = 36;

설명

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

예시 2
입력:
n = 89

예상 출력:
expected = 89
입력:
long long n = 89;

예상 출력:
long long expected = 89;
입력:
long n = 89;

예상 출력:
long expected = 89;

설명

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

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.