#include <bits/stdc++.h>
using namespace std;
using namespace std;
int period(const string &str) {
  int n = str.length(), m = str.length();
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
        int j;
        for (j = 0; j < m - m / i && str[j] == str[j + m / i]; ++j)
          ;
        if (j != m - m / i) break;
        m /= i;
      }
      while (n % i == 0) n /= i;
    }
  }
  int j;
  for (j = 0; j < m - m / n && str[j] == str[j + m / n]; ++j)
    ;
  if (j == m - m / n) m /= n;
  return m;
}
int main() {
  string s[2];
  int d[2];
  for (long long(i) = (0); (i) < (2); ++(i)) {
    cin >> s[i];
    d[i] = period(s[i]);
  }
  if (s[0].substr(0, d[0]) != s[1].substr(0, d[1]))
    cout << 0 << '\n';
  else {
    for (long long(i) = (0); (i) < (2); ++(i)) d[i] = s[i].length() / d[i];
    int ret = 0;
    for (int i = 1; i <= d[0]; ++i)
      if (d[0] % i == 0 && d[1] % i == 0) {
        ++ret;
      }
    cout << ret << '\n';
  }
}
