#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int in[N];
int main() {
  string x, y;
  cin >> x >> y;
  int n = x.size(), m = y.size();
  vector<int> vec, divs;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      int k = n / i;
      vec.emplace_back(i);
      if (k != i) vec.emplace_back(k);
    }
  }
  sort(vec.begin(), vec.end());
  for (int i = 1; i * i <= m; ++i)
    if (m % i == 0) {
      if (binary_search(vec.begin(), vec.end(), i)) divs.emplace_back(i);
      int k = m / i;
      if (k != i and binary_search(vec.begin(), vec.end(), k))
        divs.emplace_back(k);
    }
  int res = 0;
  for (int &z : divs) {
    int cnt = 0;
    string sub = x.substr(0, z);
    size_t pos = x.find(sub);
    while (pos != string::npos) {
      cnt++;
      pos = x.find(sub, pos + z);
    }
    if (cnt * z != n) continue;
    cnt = 0;
    pos = y.find(sub);
    while (pos != string::npos) {
      cnt++;
      pos = y.find(sub, pos + z);
    }
    if (cnt * z != m) continue;
    res++;
  }
  printf("%d\n", res);
}
