#include <bits/stdc++.h>
using namespace std;
vector<int> v, u, w;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  string a, b;
  cin >> a >> b;
  int n = a.size();
  int m = b.size();
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (m % i == 0) {
      u.push_back(i);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < u.size(); j++) {
      if (v[i] == u[j]) {
        w.push_back(v[i]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < w.size(); i++) {
    bool ok = 0;
    for (int j = 0; j < a.size() - w[i]; j++) {
      if (a[j] != a[j + w[i]]) ok = 1;
    }
    for (int j = 0; j < b.size() - w[i]; j++) {
      if (b[j] != b[j + w[i]]) ok = 1;
    }
    for (int j = 0; j < w[i]; j++) {
      if (a[j] != b[j]) ok = 1;
    }
    if (!ok) ans++;
  }
  cout << ans;
  return 0;
}
