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;}