#include <bits/stdc++.h>
using namespace std;
int del[1000005];
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int len1 = s1.size();
  int len2 = s2.size();
  if (len2 > len1) {
    string tmp = s1;
    s1 = s2;
    s2 = tmp;
    int tmplen = len1;
    len1 = len2;
    len2 = tmplen;
  }
  int count = 0;
  int i, j;
  for (i = len2; i >= 1; i--) {
    if (len1 % i == 0 && len2 % i == 0) {
      del[count] = i;
      count++;
    }
  }
  int answ = 0;
  for (i = 0; i < count; i++) {
    string s;
    for (j = 0; j < del[i]; j++) {
      s += s2[j];
    }
    int x = len1 / del[i];
    int xx = len2 / del[i];
    string ss = s;
    string sss = s;
    for (j = 1; j < x; j++) {
      ss += s;
      if (j < xx) {
        sss += s;
      }
    }
    if (s1 == ss && s2 == sss) {
      answ++;
    }
  }
  cout << answ;
}
