Ultraviolet A 550: multiplying by rotation

Source: Internet
Author: User

This question can be pushed forward to the number of all BITs by the known last bits of the first multiplier.

For example:

The given base number is 10, the last digit of the first multiplier is 7, and the second multiplier is 4.

List the following formula:

7

X 4

-------------------------- The carry value is 0.

Next, you will get:

87

X 4

-------------------------- Carry 2

8

Next step:

487

X 4

-------------------------- The carry value is 3.

48

Next step:

9487

X 4

-------------------------- Carry is 1

948

Next step:

79487

X 4

-------------------------- The carry value is 3.

7948

Next step:

179487

X 4

-------------------------- The carry value is 3.

17948

Next step:

179487

X 4

-------------------------- The carry value is 3.

717948

So far, the first multiplier is obtained.

This question can be simulated in this way to obtain the result.

My code is as follows:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){int base,d,f;// base, last significant digit of the first factor, the second factorwhile(cin >> base >> d >> f){int count = 0;//count for the first factor's digits numberint product, carry, next_digit;//product of next_digit and f, carry of product baseed on base, next digit of the fist factornext_digit = d;carry = 0;while(1){count++;product = next_digit*f;if (product+carry == d){break;}next_digit = (product+carry)%base;carry = (product+carry)/base;}cout << count << endl;}return 0;}

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.