Repeated Unit Divisibility | Java program to find least value of k for which R ( k ) is divisible by n ; To find least value of k ; To check n is coprime or not ; to store the R ( k ) mod n and 10 ^ k mod n value ; Driver code
import java . util . * ; class GFG { public static int repUnitValue ( int n ) { if ( n % 2 == 0 n % 5 == 0 ) return 0 ; int rem = 1 ; int power = 1 ; int k = 1 ; while ( rem % n != 0 ) { k ++ ; power = power * 10 % n ; rem = ( rem + power ) % n ; } return k ; } public static void main ( String [ ] args ) { int n = 13 ; System . out . println ( repUnitValue ( n ) ) ; } }