#include <bits/stdc++.h>
using namespace std;
string A, B;
bool is_divisor(const string &a, const string &b) {
  int sa = a.size(), sb = b.size();
  for (int i = 0; i < sb; i += sa) {
    if (b.substr(i, sa) != a) return false;
  }
  return true;
}
int process(const string &a, const string &b) {
  int sz = a.size();
  vector<int> divi;
  for (int i = 1; i < sqrt(sz) + 1; ++i) {
    if (sz % i == 0) {
      divi.push_back(i);
      if (i * i != sz) divi.push_back(sz / i);
    }
  }
  set<string> s;
  for (int i = 0; i < divi.size(); ++i)
    if (is_divisor(a.substr(0, divi[i]), a)) s.insert(a.substr(0, divi[i]));
  sz = b.size();
  divi.clear();
  for (int i = 1; i < sqrt(sz) + 1; ++i) {
    if (sz % i == 0) {
      divi.push_back(i);
      if (i * i != sz) divi.push_back(sz / i);
    }
  }
  int ans = 0;
  set<string> ss;
  for (int i = 0; i < divi.size(); ++i)
    if (is_divisor(b.substr(0, divi[i]), b)) ss.insert(b.substr(0, divi[i]));
  for (string a : s)
    if (ss.find(a) != ss.end()) ++ans;
  return ans;
}
int main() {
  char a[100001];
  scanf(" %s", a);
  A = string(a);
  scanf(" %s", a);
  B = string(a);
  cout << process(A, B) << endl;
  return 0;
}
