Find length of period in decimal value of 1 / n | Function to find length of period in 1 / n ; Find the ( n + 1 ) th remainder after decimal point in value of 1 / n ; Store ( n + 1 ) th remainder ; Count the number of remainders before next occurrence of ( n + 1 ) ' th ▁ ▁ remainder ▁ ' d ' ; Driver Code
< ? php function getPeriod ( $ n ) { $ rem = 1 ; for ( $ i = 1 ; $ i <= $ n + 1 ; $ i ++ ) $ rem = ( 10 * $ rem ) % $ n ; $ d = $ rem ; $ count = 0 ; do { $ rem = ( 10 * $ rem ) % $ n ; $ count ++ ; } while ( $ rem != $ d ) ; return $ count ; } echo getPeriod ( 3 ) , " STRNEWLINE " ; echo getPeriod ( 7 ) , " STRNEWLINE " ; ? >