Count the number of common divisors of the given strings | Function that returns true if sub - string s [ 0. . . k ] is repeated a number of times to generate string s ; Function to return the count of common divisors ; If the length of the sub - string divides length of both the strings ; If prefixes match in both the strings ; If both the strings can be generated by repeating the current prefix ; Driver code
function check ( s , k ) { for ( var i = 0 ; i < s . length ; i ++ ) if ( s [ i ] != s [ i % k ] ) return false ; return true ; } function countCommonDivisors ( a , b ) { var ct = 0 ; var n = a . length , m = b . length ; for ( var i = 1 ; i <= Math . min ( n , m ) ; i ++ ) { if ( n % i == 0 && m % i == 0 ) if ( a . substring ( 0 , i ) == b . substring ( 0 , i ) ) if ( check ( a , i ) && check ( b , i ) ) ct ++ ; } return ct ; } var a = " " , b = " " H2 : I6 ; document . write ( countCommonDivisors ( a , b ) ) ;