알고리즘/BOJ
[2331번] 반복수열
남현경
2018. 7. 30. 22:12
#include#include #include using namespace std; int A, P; vector D; int next_A, cnt; int solve() { D.push_back(A); while (1) { while (A != 0) { next_A += (int)pow(A % 10, P); A /= 10; } for (int i = 0; i < D.size(); i++) { if (next_A == D[i]) { return i; } } D.push_back(next_A); A = next_A; next_A = 0; } } int main() { cin >> A >> P; cout << solve(); return 0; }