~cpp // no550 - Multiplying by Rotation #include <iostream> using namespace std; int main() { int base, lsd, factor; // 진수, 마지막자리수, 곱셈수 int carryIn, carryOut; int temp; int nDigit; while (cin >> base >> lsd >> factor) { if (lsd == 0) { cout << "1\n"; continue; } temp = lsd; carryIn = (temp * factor) / base; temp = (temp * factor) % base; nDigit = 2; while (true) { carryOut = (temp * factor + carryIn) / base; temp = (temp * factor + carryIn) % base; if (carryOut == 0 && temp == lsd) { cout << nDigit << endl; break; } nDigit++; carryIn = carryOut; } } return 0; }