550-multiplying by rotation
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_ problem&problem=491
Warning:not all numbers in this problem are decimal numbers!
Multiplication of natural numbers in the general is a cumbersome operation. In some cases however the product can is obtained by moving the last digit to the front.
example:179487 * 4 = 717948
The course this property is depends on the numbersystem for you, in the above example we used the decimal representation. In base 9 We have a shorter example:
* 4 = (base 9)
As (9 * 1 + 7) * 4 = 7 * 9 + 1
Input
The input for your program is a textfile. Each line consists of three numbers separated by a space:the base of the number system, the least significant digit of th E-Factor, and the second factor. This second factor are one digit only hence less than the base. The input file ends with the standard end-of-file marker.
Output
Your program determines for each input line the number of digits of the smallest a, the factor with the. The Output-file is also a textfile. Each line contains the "answer for the" corresponding input line.
Sample Input
10 7 4
9 7 4
17 14 12
Sample Output
6
2
4
Learn English:
The least significant digit of the The
The least significant bit of the first multiplier (that is, the lowest bit)
Idea: Constantly multiply the two lowest bit a,b until the carry is a
Explain how the last example of 4 is calculated:
Complete code:
/*0.028s*/
#include <cstdio>
int main ()
{
int base, FIN, A, B, C, count, ans;
while (~SCANF ("%d%d%d", &base, &fin, &b))
{
a = fin;
c = Count = 0;
Do
{
ans = a * b + C;
A = ans% base, C = Ans/base;
++count;
}
while (ans!= fin);
printf ("%d\n", count);
}
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/