#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  int t, i, j, k, l, m;
  map<string, int> mp;
  cin >> s >> s1;
  l = s.size();
  m = s1.size();
  for (i = 1; i <= l; i++) {
    if (l % i == 0 && m % i == 0) {
      string s2 = s.substr(0, i);
      int flag = 0;
      for (j = i; j < l; j = j + i) {
        string s3 = s.substr(j, i);
        if (s3 == s2)
          continue;
        else {
          flag = 1;
          break;
        }
      }
      if (flag)
        continue;
      else
        mp[s2]++;
    }
  }
  int count = 0;
  for (i = 1; i <= m; i++) {
    if (l % i == 0 && m % i == 0) {
      string s2 = s1.substr(0, i);
      int flag = 0;
      for (j = i; j < m; j = j + i) {
        string s3 = s1.substr(j, i);
        if (s3 == s2)
          continue;
        else {
          flag = 1;
          break;
        }
      }
      if (flag)
        continue;
      else {
        if (mp[s2]) count++;
      }
    }
  }
  cout << count;
  return 0;
}
