#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int n1 = s1.length(), n2 = s2.length();
  int res = 0;
  for (int i = 1; i <= min(n1, n2); ++i) {
    if (n1 % i || n2 % i) continue;
    bool b = 1;
    for (int j = 0; j < n1; ++j) {
      if (s1[j] != s1[j % i]) {
        b = 0;
        break;
      }
    }
    if (!b) continue;
    for (int j = 0; j < n2; ++j) {
      if (s2[j] != s2[j % i]) {
        b = 0;
        break;
      }
    }
    if (!b) continue;
    for (int j = 0; j < i; ++j) {
      if (s1[j] != s2[j]) {
        cout << res;
        return 0;
      }
    }
    ++res;
  }
  cout << res;
  return 0;
}
