#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s1, s2;
  cin >> s1 >> s2;
  string l1, l2;
  bool divisor;
  for (int i = 1; i <= sqrt(s1.length()); ++i) {
    if (s1.length() % i != 0) continue;
    l1 = "";
    divisor = true;
    for (int j = 0; j < s1.length(); ++j) {
      if (j < i) {
        l1 += s1[j];
      } else if (s1[j] != l1[j % i]) {
        divisor = false;
      }
    }
    if (divisor) {
      break;
    }
  }
  if (!divisor) {
    for (int i = sqrt(s1.length()); i >= 1; --i) {
      if (s1.length() % i != 0) continue;
      int x = s1.length() / i;
      l1 = "";
      divisor = true;
      for (int j = 0; j < s1.length(); ++j) {
        if (j < x) {
          l1 += s1[j];
        } else if (s1[j] != l1[j % x]) {
          divisor = false;
        }
      }
      if (divisor) {
        break;
      }
    }
  }
  for (int i = 1; i <= sqrt(s2.length()); ++i) {
    if (s2.length() % i != 0) continue;
    l2 = "";
    divisor = true;
    for (int j = 0; j < s2.length(); ++j) {
      if (j < i) {
        l2 += s2[j];
      } else if (s2[j] != l2[j % i]) {
        divisor = false;
      }
    }
    if (divisor) {
      break;
    }
  }
  if (!divisor) {
    for (int i = sqrt(s2.length()); i >= 1; --i) {
      if (s2.length() % i != 0) continue;
      int x = s2.length() / i;
      l2 = "";
      divisor = true;
      for (int j = 0; j < s2.length(); ++j) {
        if (j < x) {
          l2 += s2[j];
        } else if (s2[j] != l2[j % x]) {
          divisor = false;
        }
      }
      if (divisor) {
        break;
      }
    }
  }
  if (l1 != l2) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = l1.length(); i <= min(s1.length(), s2.length());
       i += l1.length()) {
    if (s1.length() % i == 0 && s2.length() % i == 0) {
      ++ans;
    }
  }
  cout << ans << endl;
}
