#include <bits/stdc++.h>
long long MOD = 1000000007;
long long inf = 10000000000;
using namespace std;
int gcd(int a, int b) {
  int c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
string s1, s2;
int main() {
  ios::sync_with_stdio(false);
  int n1, n2, x, ans = 0, i, j;
  bool valid;
  cin >> s1 >> s2;
  n1 = s1.size();
  n2 = s2.size();
  x = gcd(n1, n2);
  for (i = 1; i <= x; i++) {
    if (n1 % i != 0 || n2 % i != 0) {
      continue;
    }
    valid = true;
    for (j = i; j < n1; j++) {
      if (s1[j] != s1[j - i]) {
        valid = false;
        break;
      }
    }
    for (j = i; j < n2; j++) {
      if (s2[j] != s2[j - i]) {
        valid = false;
        break;
      }
    }
    for (j = 0; j < i; j++) {
      if (s1[j] != s2[j]) {
        valid = false;
        break;
      }
    }
    if (valid == false) {
      continue;
    }
    ans += 1;
  }
  cout << ans;
  return 0;
}
