소ê°� ¶
2005/03/05 Accepted 0:00.074 64
1학년 때 풀어서 í‹€ë ¸ì—ˆë�˜ ë¬¸ì œë¥¼ 다시 풀어보았다. ì�¼ë‹¨ ì�´ë�™ê³±ì…ˆì�˜ 규칙성ì�„ 연습장ì—� ë�„ì �ì�´ëŠ” ë�„중 쉽게 ë°œê²¬í• ìˆ˜ ìžˆì—ˆê³ , 간단히 사칙연산으로 êµ¬í˜„í• ìˆ˜ 있었다. 마지막 ìž�리숫ìž�ê°€ 0ì�¼ 경우ì�˜ 예외처리를 í•´ 준 후 바로 통과.
1학년 때 풀어서 í‹€ë ¸ì—ˆë�˜ ë¬¸ì œë¥¼ 다시 풀어보았다. ì�¼ë‹¨ ì�´ë�™ê³±ì…ˆì�˜ 규칙성ì�„ 연습장ì—� ë�„ì �ì�´ëŠ” ë�„중 쉽게 ë°œê²¬í• ìˆ˜ ìžˆì—ˆê³ , 간단히 사칙연산으로 êµ¬í˜„í• ìˆ˜ 있었다. 마지막 ìž�리숫ìž�ê°€ 0ì�¼ 경우ì�˜ 예외처리를 í•´ 준 후 바로 통과.
코드 ¶
~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;
}










