#include <bits/stdc++.h>
using namespace std;
string mul(string s, long long n) {
  string ans = "";
  for (long long i = 0; i < n; i++) ans += s;
  return ans;
}
signed main() {
  string a, b;
  cin >> a >> b;
  if (b.size() > a.size()) {
    string temp = a;
    a = b;
    b = temp;
  }
  long long x = a.size(), y = b.size();
  long long ans = 0;
  for (long long i = 1; i <= x; i++) {
    if ((x % i == 0) && (y % i == 0)) {
      string temp = a.substr(0, i);
      long long t1 = x / i, t2 = y / i;
      if (mul(temp, t1) == a && mul(temp, t2) == b) {
        ans++;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
