#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
string s1, s2;
bool check(int l, string s) {
  int n = (int)s.size();
  bool f = 1;
  for (int i = (int)0; i <= (int)n - 1; ++i) f &= (s[i] == s[i % l]);
  return f;
}
int main(int argc, char const *argv[]) {
  cin >> s1 >> s2;
  int n = (int)s1.size(), m = (int)s2.size();
  int cnt = 0;
  for (int i = 1; i <= n && i <= m && s1[i - 1] == s2[i - 1]; ++i) {
    if (n % i || m % i) continue;
    if (check(i, s1) && check(i, s2)) ++cnt;
  }
  printf("%d\n", cnt);
  return 0;
}
