#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
const int OO = 1e9;
const double PI = acos(-1);
long long fastpow(long long b, long long e) {
  if (!e) return 1;
  long long ret = fastpow(b, e / 2);
  ret = (ret * ret) % mod;
  if (e % 2) ret = (ret * b) % mod;
  return ret;
}
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  vector<int> v1, v2;
  for (int i = 1; i <= s1.size(); i++) {
    if (s1.size() % i == 0) v1.push_back(i);
  }
  for (int i = 1; i <= s2.size(); i++) {
    if (s2.size() % i == 0) v2.push_back(i);
  }
  string t;
  map<string, int> m;
  for (int i = 0, j = 0; i < v1.size(); i++) {
    for (int k = 0; k < v1[i] - (i > 0 ? v1[i - 1] : 0); k++, j++)
      t.push_back(s1[j]);
    bool ok = 1;
    for (int l = 0; l < s1.size(); l++) {
      if (s1[l] != t[l % t.size()]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      m[t]++;
    }
  }
  t = "";
  for (int i = 0, j = 0; i < v2.size(); i++) {
    for (int k = 0; k < v2[i] - (i > 0 ? v2[i - 1] : 0); k++, j++)
      t.push_back(s2[j]);
    bool ok = 1;
    for (int l = 0; l < s2.size(); l++) {
      if (s2[l] != t[l % t.size()]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      m[t]++;
    }
  }
  int cntr = 0;
  for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    if (it->second == 2) cntr++;
  }
  cout << cntr;
  return 0;
}
