UVa Multiplying by rotation: analog multiplication

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.