#include <bits/stdc++.h>
using namespace std;
int l1[100010], l2[100010];
int main() {
  cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  int x1, x2, y1, y2;
  for (int i = 1, k = 0; i < s.size(); i++) {
    while (k > 0 && s[i] != s[k]) k = l1[k - 1];
    if (s[i] == s[k])
      l1[i] = ++k;
    else
      l1[i] = k;
  }
  y1 = s.size() - l1[s.size() - 1];
  if (s.size() % y1 != 0)
    y1 = s.size(), x1 = 1;
  else
    x1 = s.size() / y1;
  for (int i = 1, k = 0; i < t.size(); i++) {
    while (k > 0 && t[i] != t[k]) k = l2[k - 1];
    if (t[i] == t[k])
      l2[i] = ++k;
    else
      l2[i] = k;
  }
  y2 = t.size() - l2[t.size() - 1];
  if (t.size() % y2 != 0)
    y2 = t.size(), x2 = 1;
  else
    x2 = t.size() / y2;
  if (s.substr(0, y1) != t.substr(0, y2)) {
    printf("0");
    return 0;
  }
  int counter = 0;
  for (int i = 1; i <= min(x1, x2); i++)
    if (x1 % i == 0 && x2 % i == 0) counter++;
  printf("%d", counter);
  return 0;
}
