#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1;
  getline(std::cin, s1);
  string s2;
  getline(std::cin, s2);
  string s;
  if (s1.length() > s2.length()) {
    s = s1;
    s1 = s2;
    s2 = s;
  }
  size_t pos;
  int l1 = 0, l2 = 0;
  string sc;
  int count = 0;
  int j = 0;
  for (int i = 1; i <= s1.length() / 2 && i <= s2.length() / 2; i++) {
    if ((s1.length() % i) != 0 || (s2.length() % i) != 0) continue;
    s = s1.substr(0, i);
    sc.clear();
    l1 = s1.length() / i;
    for (j = 0; j < l1; j++) sc += s;
    if (sc.compare(s1) != 0) continue;
    l2 = s2.length() / i;
    for (j = 0; j < (l2 - l1); j++) sc += s;
    if (sc.compare(s2) != 0) continue;
    count++;
  }
  sc.clear();
  if ((s2.length() % s1.length()) == 0) {
    l1 = s2.length() / s1.length();
    for (j = 0; j < l1; j++) sc += s1;
    if (s2.compare(sc) == 0) count++;
  }
  cout << count << endl;
  return 0;
}
