#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, l1, l2, i, j, cnt = 0, p1, p2, f = 0;
  string s1, s2;
  cin >> s1 >> s2;
  if (s1.size() > s2.size()) swap(s1, s2);
  l1 = s1.size(), l2 = s2.size();
  vector<int> div;
  for (i = 1; i * i <= l1; i++) {
    if (i * i == l1)
      div.push_back(i);
    else if (l1 % i == 0) {
      div.push_back(i);
      div.push_back(l1 / i);
    }
  }
  sort(div.begin(), div.end());
  for (i = 0; i < div.size(); i++) {
    if (l2 % div[i] == 0) {
      p1 = 0;
      p2 = 0;
      f = 0;
      while (p1 < l1 || p2 < l2) {
        if (p1 < l1) {
          if (s1.substr(0, div[i]) != s1.substr(p1, div[i])) {
            f = 1;
            break;
          }
        }
        if (p2 < l2) {
          if (s1.substr(0, div[i]) != s2.substr(p2, div[i])) {
            f = 1;
            break;
          }
        }
        p1 += div[i];
        p2 += div[i];
      }
      if (f == 0) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
