#include <bits/stdc++.h>
using namespace std;
string s1, s2;
bool check(string a, string b) {
  int j = 0;
  for (int k = 0; k < b.length() / a.length(); k++)
    for (int i = 0; i < a.length(); i++)
      if (a[i] == b[j])
        j++;
      else
        return 0;
  return 1;
};
int main() {
  getline(cin, s1);
  getline(cin, s2);
  if (s1.length() > s2.length()) {
    string temp;
    temp = s1;
    s1 = s2;
    s2 = temp;
  };
  int sum = 0;
  for (int i = s1.length(); i > 0; i--)
    if (s1.length() % i == 0 && s2.length() % i == 0) {
      string temp = s1;
      temp.erase(temp.begin() + i, temp.end());
      if (check(temp, s1) && check(temp, s2)) {
        sum++;
      };
    };
  cout << sum;
  return 0;
}
