#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2, str1, str2, str1f, str2f;
  cin >> s1 >> s2;
  long long int l1 = s1.length();
  long long int l2 = s2.length();
  long long int c = 0, i, j;
  for (i = 1; i <= min(l1, l2); i++) {
    str1 = "";
    str2 = "";
    str1f = "";
    str2f = "";
    if (l1 % i == 0 && l2 % i == 0) {
      for (j = 0; j < i; j++) str1 += s1.at(j);
      for (j = 1; j <= l1 / i; j++) {
        str1f += str1;
      }
      for (j = 0; j < i; j++) str2 += s2.at(j);
      for (j = 1; j <= l2 / i; j++) {
        str2f += str2;
      }
      if (str1f == s1 && str2f == s2 && str1 == str2) c++;
    }
  }
  cout << c << endl;
}
