TopCoder

FHVirus
想像不出自己 AC 的題目是實作不出來的!

User's AC Ratio

100.0% (111/111)

Submission's AC Ratio

81.8% (130/159)

Tags

Description

一個$d$位數整數$N = n_1n_2n_3\ldots n_d$,$n_i \in \{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 \}$被稱為自戀數(narcissistic number)若$N = n_1^ d + n_2^ d + n_3^ d + \ldots + n_d^ d$。例如3位數整數$153$是自戀數因為$153 = 1^ 3+5^ 3+3^ 3$,而4位數整數$1321$不是自戀數因為$1^ 4+3^ 4+2^ 4+1^ 4 = 99$非$1321$。
非十進位制數字數字也會有自戀數,例如3進位制數字$(122)_3 = 17$且$1^ 3+2^ 3+2^ 3 = 17$,或5進位制數字$(3134)_5 = 419$且$3^ 4+1^ 4+3^ 4+4^ 4 = 419$。
請寫一個程式判斷一整數是否為自戀數。

Input Format

第一列有兩個非負整數 $b$與 $N$,代表 $N$為$b$進位制整數。

Output Format

若輸出之整數為自戀數,輸出YES,若否則輸出NO

Sample Input 1

10 153

Sample Output 1

YES

Sample Input 2

10 1321

Sample Output 2

NO

Sample Input 3

3 122

Sample Output 3

YES

Sample Input 4

5 3134

Sample Output 4

YES

Hints

本題共有共有二個子題,每一子題可有多筆測試資料:
第一子題的測試資料$b = 10$,$N$最大為8位數整數,全部解出可獲83分。
第二子題的測試資料$2\leq b \leq 10$,$N$最大為8位數整數,全部解出可獲17分。

Problem Source

106學年度高級中學資訊學科能力競賽決賽 程式設計試題第二題

Subtasks

No. Testdata Range Score
1 0~14 83
2 15~29 17

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 500 524288 262144 1
1 500 524288 262144 1
2 500 524288 262144 1
3 500 524288 262144 1
4 500 524288 262144 1
5 500 524288 262144 1
6 500 524288 262144 1
7 500 524288 262144 1
8 500 524288 262144 1
9 500 524288 262144 1
10 500 524288 262144 1
11 500 524288 262144 1
12 500 524288 262144 1
13 500 524288 262144 1
14 500 524288 262144 1
15 500 524288 262144 2
16 500 524288 262144 2
17 500 524288 262144 2
18 500 524288 262144 2
19 500 524288 262144 2
20 500 524288 262144 2
21 500 524288 262144 2
22 500 524288 262144 2
23 500 524288 262144 2
24 500 524288 262144 2
25 500 524288 262144 2
26 500 524288 262144 2
27 500 524288 262144 2
28 500 524288 262144 2
29 500 524288 262144 2