-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2331.cpp
More file actions
56 lines (51 loc) · 747 Bytes
/
2331.cpp
File metadata and controls
56 lines (51 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 2331. 반복수열
// 2019.08.05
// 수학
#include<iostream>
#include<map>
#include<cmath>
using namespace std;
int d[10000];
// 입력받은 수의 각 자리수를 p제곱해서 더한 값을 반환하는 함수
int go(int num, int p)
{
int ans = 0;
while (num > 0)
{
ans += pow(num % 10, p);
num /= 10;
}
return ans;
}
int main()
{
int a, p;
cin >> a >> p;
map<int, bool> m;
m[a] = true;
int cnt = 1;
int re = -1;
int cur = go(a,p);
d[0] = a;
while (1)
{
// 이미 한번 나온 숫자라면 종료
if (m[cur]==true)
{
re = cur;
break;
}
d[cnt++]=cur;
m[cur] = true;
cur = go(cur, p);
}
for (int i = 0; i < cnt; i++)
{
if (d[i] == re)
{
cout << i << endl;
break;
}
}
return 0;
}