U E D R , A S I H C RSS

Multiplying By Rotation/곽세환

소감

통과X

소스

~cpp 
#include <iostream>
#include <cmath>
using namespace std;

const int MAX = 20;	// 최대 20자리까지

void main()
{
	int base, factor1, factor2;
	cin >> base >> factor1 >> factor2;
	
	int number[MAX] = {0};
	number[0] = factor1;
	int number_jarisu = 1;

	int dec, dec2;

	while (true)
	{
		dec = 0;
		dec2 = 0;
		for (int i = 0; i < number_jarisu; i++)
			dec += number[i] * pow(base, i);
		for (i = 1; i < number_jarisu; i++)
			dec2 += number[i] * pow(base, i - 1);
		dec2 += number[0] * pow(base, number_jarisu - 1);

		if (dec * factor2 == dec2)
			break;

		number[1]++;

		for (i = 1; i < number_jarisu; i++)
		{
			if (number[i] == base)
			{
				number[i + 1]++;
				number[i] = 0;
			}
			else
				break;
		}
		if (i == number_jarisu)
				number_jarisu++;

	}
	cout << number_jarisu << endl;
	//for (int i = number_jarisu - 1; i >= 0; i--)
	//	cout << number[i] << " ";
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:49
Processing time 0.0172 sec