Question:
When dividing two integers, sometimes a recurring decimal is generated. The recurring part is called: recurring section.
For example, 11/13=6=>0.846153846153..... The loop section is [846153] and there are 6 bits in total.
When dividing two integers, sometimes a recurring decimal is generated. The recurring part is called: recurring section.
For example, 11/13=6=>0.846153846153..... The loop section is [846153] and there are 6 bits in total.
The following method can find the length of the loop section.
Please read the code carefully and fill in the missing code in the underlined part.
public static int f(int n, int m) { n = n % m; Vector v = new Vector(); for (;;) { //Add the remainder of each time to the Vector collection v.add(n); n *= 10; n = n % m; if (n == 0) return 0; //If the remainder is the same as a remainder added before, it means the loop starts if (v.indexOf(n) >= 0) return v.size()-v.indexOf(n); //This is the code to fill in the line drawing part } }