A number which consists entirely repeated number of times one is said to be Repeated Unit. We shall define R(k) of length k repeated unit number. For example, R(6) = 111111.
For a given number n, a positive integer and GCD(n, 10) = 1, there exists a value k such that R(k) is divisible by n. Now let A(n) be the least such value of k i.e. A(n) = k.
Thus, we have to find for the given value of n the least such value of A(n) for which k times repeated one is divided by n.
Input : n = 7 Output : A(7) = 6 A(7) = 6 means 6 times one i.e. (111111) is divided by 7. Input : n = 41 Output : A(41) = 5 A(41) = 5 means 5 times one i.e. (11111) is divided by 41.
First of all if the given number should be coprime with 10 otherwise return 0.
If the given number is coprime with 10 then we have to find smallest number k such that R(k) = 0 mod n.
Consider the repeated units R(1), R(2), R(3), R(4) and so on. For each repeated unit R(j) suppose when calculating remainder of R(j) divided by n. There are n conceivable remainders. We get that R(i), R(j) where i < j have same remainder when divided by n. It follows that R(j) – R(i) is divided by n. This difference is repeated unit multiplied by power of 10. But, as we know that 10 and n are relatively prime, n divides R(k).
- Check divisibility by 7
- Sub-string Divisibility by 11 Queries
- Sub-string Divisibility by 3 Queries
- Divisibility by 12 for a large number
- Check divisibility in a binary stream
- Check if a large number is divisibility by 15
- Divisibility by 64 with removal of bits allowed
- To check divisibility of any large number by 999
- Divisibility by 3 where each digit is the sum of all prefix digits modulo 10
- Maximize profit when divisibility by two numbers have associated profits
- Maximum path sum for each position with jumps under divisibility condition
- Sum of integers upto N with given unit digit
- Sum of integers upto N with given unit digit (Set 2)
- Repeated subtraction among two numbers
- Find the unit place digit of sum of N factorials
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.