#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, c, d;
};
bool cmp(const node &first, const node &sec) {
  if (first.a != sec.a) return first.a < sec.a;
  return first.b < sec.b;
}
bool operator<(const node &left, const node &right) { return left.b > right.b; }
int len, len1, i, l, l1, c, ans, flag, flag1, j;
string str, str1;
vector<int> v;
int main() {
  cin >> str;
  cin >> str1;
  l = str.length();
  l1 = str1.length();
  if (l > l1) {
    swap(str, str1);
    swap(l, l1);
  }
  for (i = 1; i <= l; i++) {
    if ((l % i == 0) && (l1 % i == 0)) v.push_back(i);
  }
  for (i = 0; i < v.size(); i++) {
    len = v[i];
    flag = 0;
    flag1 = 0;
    string b = str.substr(0, len);
    for (j = 0; j < l; j = j + len) {
      string a = str.substr(j, len);
      if (a != b) flag = 1;
    }
    for (j = 0; j < l1; j = j + len) {
      string a = str1.substr(j, len);
      if (a != b) flag1 = 1;
    }
    if ((flag + flag1) == 0) ans++;
  }
  cout << ans;
  return 0;
}
