#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int k, ans;
double eps = 0.01;
bool ok(int l) {
  if (s1.compare(0, l, s2, 0, l) != 0) {
    return false;
  }
  for (int i = 0; i < s1.size(); i += l) {
    if (s1.compare(0, l, s1, i, l) != 0) {
      return false;
    }
  }
  for (int i = 0; i < s2.size(); i += l) {
    if (s2.compare(0, l, s2, i, l) != 0) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> s1 >> s2;
  k = min(s1.size(), s2.size());
  for (int i = 1; i <= sqrt(k + eps); i++) {
    if (s1.size() % i == 0 && s2.size() % i == 0 && ok(i)) {
      ans++;
    }
    if (s1.size() % (k / i) == 0 && s2.size() % (k / i) == 0 && i != k / i &&
        ok(k / i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
