#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, m, x, c;
bool check(string a, string b, long long int k) {
  for (auto g = 0; g < a.size() - k; g++) {
    if (a[g] != a[g + k]) {
      return false;
    }
  }
  for (auto g = 0; g < a.size(); g++) {
    if (a[g] != b[g]) {
      return false;
    }
  }
  for (auto g = 0; g < b.size() - k; g++) {
    if (b[g] != b[g + k]) {
      return false;
    }
  }
  return true;
}
void solve() {
  string a, b;
  cin >> a;
  cin >> b;
  if (a.size() > b.size()) {
    swap(a, b);
  }
  if (a.size() == b.size() && a != b) {
    cout << "0";
    return;
  }
  n = a.size();
  vector<long long int> fac;
  for (i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i != n / i) {
        fac.push_back(i);
        fac.push_back(n / i);
      } else
        fac.push_back(i);
    }
  }
  sort(fac.begin(), fac.end());
  for (i = 0; i < fac.size(); i++) {
    if (check(a, b, fac[i])) {
      long long int ans = 0;
      for (auto g = 1; g <= a.size() / fac[i]; g++) {
        if (a.size() % (g * fac[i]) == 0 && b.size() % (g * fac[i]) == 0) ans++;
      }
      cout << ans;
      return;
    }
  }
  cout << "0";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int T = 1;
  while (T--) {
    solve();
    cout << endl;
  }
  return 0;
}
