#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, l1, l2, k, num = 0, j1, j2;
  string s1, s2, s3;
  cin >> s1 >> s2;
  l1 = (s1).size();
  l2 = (s2).size();
  i = 0;
  while (i < l1 && i < l2 && (s1)[i] == (s2)[i]) i++;
  k = i;
  for (i = 1; i <= k; i++) {
    if (l1 % i == 0 && l2 % i == 0) {
      j1 = i;
      while (j1 < l1 && (s1)[j1 % i] == (s1)[j1]) j1++;
      if (j1 == l1) {
        j2 = i;
        while (j2 < l2 && (s2)[j2 % i] == (s2)[j2]) j2++;
        if (j2 == l2) num++;
      }
    }
  }
  cout << num;
  return 0;
}
