#include <bits/stdc++.h>
using namespace std;
int rc(int x) {
  int r = 1;
  while (r * r <= x) {
    r++;
  }
  return r;
}
int bw[110];
int main() {
  string a, b;
  cin >> a >> b;
  int la = a.size();
  int lb = b.size();
  if (lb < la) {
    swap(a, b);
    swap(la, lb);
  }
  int r = 0;
  for (int i = 1; i <= la; i++) {
    if (la % i != 0) continue;
    if (lb % i != 0) continue;
    string t = a.substr(0, i);
    bool esd = true;
    for (int j = 0; j < lb; j += i) {
      if (t != b.substr(j, i)) {
        esd = false;
        break;
      }
      if (j + i <= la) {
        if (t != a.substr(j, i)) {
          esd = false;
          break;
        }
      }
    }
    if (esd) r++;
  }
  cout << r << endl;
}
