U E D R , A S I H C RSS

Multiplying By Rotation/문보창

2005/03/05 Accepted 0:00.074 64
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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:49
Processing time 0.0128 sec