#include <iostream>
#define PB 163
#define MOD 1000000007
#define MAX 100000
#define ll long long
using namespace std;
ll ppow[MAX+1];
ll h1[MAX+1];
ll h2[MAX+1];
int main()
{
ppow[0] = 1;
for (int i = 1; i < MAX+1; ++i)
ppow[i] = (ppow[i-1] * PB) % MOD;
string s1, s2;
s1.erase(); s2.erase();
cin >> s1; cin >> s2;
h1[0] = s1[0] - 'a';
//cout << h1[0] << " ";
for (int i = 1; i < s1.size(); ++i)
{
h1[i] = (((h1[i-1] * PB) % MOD) + (s1[i] - 'a')) % MOD;
//cout << h1[i] << " " ;
}
//cout << '\n';
h2[0] = s2[0] - 'a';
//cout << h2[0] << " ";
for (int i = 1; i < s2.size(); ++i)
{
h2[i] = (((h2[i-1] * PB) % MOD) + (s2[i] - 'a')) % MOD;
//cout << h2[i] << " " ;
}
//cout << '\n';
int ans = 0;
int l1 = s1.size(), l2 = s2.size();
for (int i = 1; i <= l1; ++i)
{
if (l1 % i == 0 && l2 % i == 0)
{
bool flag = true;
ll temp = h1[i-1];
for (int j = 0; j < l1; j = j + i)
if (temp != (h1[j+i-1] - ((h1[j-1] * ppow[i]) % MOD)))
flag = false;
for (int j = 0; j < l2; j = j + i)
{
//if (i == 4)
// cout << (h2[j+i-1] - ((h2[j-1] * ppow[i]) % MOD)) << "check" << '\n';
if (temp != (h2[j+i-1] - ((h2[j-1] * ppow[i]) % MOD)))
flag = false;
}
ans += flag;
}
}
cout << ans << '\n';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIFBCIDE2MwojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgTUFYIDEwMDAwMAojZGVmaW5lIGxsIGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKbGwgcHBvd1tNQVgrMV07CmxsIGgxW01BWCsxXTsKbGwgaDJbTUFYKzFdOwoKaW50IG1haW4oKSAKewogICAgcHBvd1swXSA9IDE7CiAgICBmb3IgKGludCBpID0gMTsgaSA8IE1BWCsxOyArK2kpCiAgICAgICAgcHBvd1tpXSA9IChwcG93W2ktMV0gKiBQQikgJSBNT0Q7CiAgICBzdHJpbmcgczEsIHMyOwoJczEuZXJhc2UoKTsgczIuZXJhc2UoKTsKICAgIGNpbiA+PiBzMTsgY2luID4+IHMyOwogICAgaDFbMF0gPSBzMVswXSAtICdhJzsKICAgIC8vY291dCA8PCBoMVswXSA8PCAiICI7CiAgICBmb3IgKGludCBpID0gMTsgaSA8IHMxLnNpemUoKTsgKytpKQogICAgewogICAgICAgIGgxW2ldID0gKCgoaDFbaS0xXSAqIFBCKSAlIE1PRCkgKyAoczFbaV0gLSAnYScpKSAlIE1PRDsKICAgICAgICAvL2NvdXQgPDwgaDFbaV0gPDwgIiAiIDsKICAgIH0KICAgIC8vY291dCA8PCAnXG4nOyAKICAgIGgyWzBdID0gczJbMF0gLSAnYSc7CiAgICAvL2NvdXQgPDwgaDJbMF0gPDwgIiAiOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBzMi5zaXplKCk7ICsraSkKICAgIHsKICAgICAgICBoMltpXSA9ICgoKGgyW2ktMV0gKiBQQikgJSBNT0QpICsgKHMyW2ldIC0gJ2EnKSkgJSBNT0Q7CiAgICAgICAgLy9jb3V0IDw8IGgyW2ldIDw8ICIgIiA7CiAgICB9CiAgICAvL2NvdXQgPDwgJ1xuJzsgCiAgICBpbnQgYW5zID0gMDsKICAgIGludCBsMSA9IHMxLnNpemUoKSwgbDIgPSBzMi5zaXplKCk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBsMTsgKytpKQogICAgewogICAgICAgIGlmIChsMSAlIGkgPT0gMCAmJiBsMiAlIGkgPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIGJvb2wgZmxhZyA9IHRydWU7CiAgICAgICAgICAgIGxsIHRlbXAgPSBoMVtpLTFdOwogICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGwxOyBqID0gaiArIGkpCiAgICAgICAgICAgICAgICBpZiAodGVtcCAhPSAoaDFbaitpLTFdIC0gKChoMVtqLTFdICogcHBvd1tpXSkgJSBNT0QpKSkKICAgICAgICAgICAgICAgICAgICBmbGFnID0gZmFsc2U7CiAgICAgICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbDI7IGogPSBqICsgaSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgLy9pZiAoaSA9PSA0KQogICAgICAgICAgICAgICAgLy8gIGNvdXQgPDwgKGgyW2oraS0xXSAtICgoaDJbai0xXSAqIHBwb3dbaV0pICUgTU9EKSkgPDwgImNoZWNrIiA8PCAnXG4nOwogICAgICAgICAgICAgICAgaWYgKHRlbXAgIT0gKGgyW2oraS0xXSAtICgoaDJbai0xXSAqIHBwb3dbaV0pICUgTU9EKSkpCiAgICAgICAgICAgICAgICAgICAgZmxhZyA9IGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGFucyArPSBmbGFnOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8ICdcbic7CiAgICByZXR1cm4gMDsKfQ==