#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
const long long xinc[] = {0, 0, 1, -1};
const long long yinc[] = {1, -1, 0, 0};
const long double PI = acos(-1.0);
const double EPS = 1e-9;
string s1, s2;
long long ans;
bool isDiv(const string& s1, const string& temp) {
  long long n = s1.size();
  long long len = temp.size();
  if (n % len != 0) return false;
  long long q = n / len;
  string p;
  for (long long i = 0; i < q; i++) p += temp;
  return (p == s1);
}
void solve() {
  cin >> s1 >> s2;
  if (s1.size() > s2.size()) swap(s1, s2);
  long long n1 = s1.size(), n2 = s2.size();
  for (long long i = 1; i * i <= n1; i++)
    if (n1 % i == 0) {
      string temp = s1.substr(0, i);
      bool valid1 = isDiv(s1, temp);
      bool valid2 = isDiv(s2, temp);
      if (valid1 && valid2) ans++;
      long long l2 = n1 / i;
      if (i * i != n1) {
        temp = s1.substr(0, l2);
        valid2 = isDiv(s2, temp);
        valid1 = isDiv(s1, temp);
        if (valid1 && valid2) ans++;
      }
    }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
