#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int n1, n2;
vector<int> divs;
void get_divs(int n, map<long long, long long>& m) {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      m[i] = 1;
      if (n / i != i) {
        if (n % (n / i) == 0) {
          m[n / i] = 1;
        }
      }
    }
  }
}
void cmn_divs(int n1, int n2) {
  map<long long, long long> m1, m2;
  get_divs(n1, m1);
  get_divs(n2, m2);
  for (map<long long, long long>::iterator it = m1.begin(); it != m1.end();
       it++) {
    if (m2[it->first]) {
      divs.push_back(it->first);
    }
  }
  sort(divs.begin(), divs.end());
}
bool check(string s1, string tmp1) {
  int k = 0, len = tmp1.length();
  for (int i = 0; i < s1.length(); i++) {
    if (s1[i] != tmp1[k]) return false;
    k++;
    if (k == len) k = 0;
  }
  return true;
}
int main() {
  cin >> s1 >> s2;
  if (s1.length() > s2.length()) {
    swap(s1, s2);
  }
  n1 = s1.length();
  n2 = s2.length();
  cmn_divs(n1, n2);
  int ans = 0;
  for (int j = 0; j < divs.size(); j++) {
    int len = divs[j];
    string tmp1 = s1.substr(0, len);
    int len2 = s2.length(), k = 0, flag = 0;
    if (!check(s1, tmp1)) {
      continue;
    }
    for (int i = 0; i < len2; i++) {
      if (s2[i] != tmp1[k]) {
        flag = 1;
        break;
      }
      k++;
      if (k == len) k = 0;
    }
    if (!flag) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
