#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    long long hs[(int)(s.length())];
    long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if (hs[j] * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = ht[i - 1] * p[tl - i];
            for (int j = 2*i - 1 ; j < tl; j+=i){
                if (ht[j] * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs && ft){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s , t;
    cin >> s >> t;
    int ans = 0;
    int sl = s.length() , tl = t.length();

    for (int i = 1; i <= min(sl , tl); i++){
        if (sl % i == 0 && tl % i == 0){
            string cur = s.substr(0 , i);
            string s1;
            string t1;
            for (int j = 0; j < sl / i; j++){
                s1 += cur;
            }
            for (int j = 0; j < tl / i; j++){
                t1 += cur;
            }
            if (s1 == s && t1 == t){
                ans++;
            }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            unsigned long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if ((hs[j] - ht[j - i]) * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = hs[i - 1] * p[tl - i];
            if (cur != ht[i - 1] * p[tl - i]){
                ft = false;
            }
            for (int j = 2*i - 1; j < tl; j+=i){
                if ((ht[j] - ht[j - i]) * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs == true && ft == true){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            unsigned long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if (hs[j] * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = ht[i - 1] * p[tl - i];
            for (int j = 2*i - 1 ; j < tl; j+=i){
                if (ht[j] * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs == true && ft == true){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());
    long long d = max(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            unsigned long long cur;
            bool f = true;
            ///
            cur = hs[i - 1] * p[d - i];
            ///
            for (int j = 2*i - 1; j < sl; j+=i){
                if ((hs[j] - hs[j - i]) * p[d - j - 1] != cur){
                    f = false;
                    break;
                }
            }
            for (int j = i - 1; j < tl; j+=i){
                if ((ht[j] - (j - i < 0 ? 0 : ht[j - i])) * p[d - j - 1] != cur){
                    f = false;
                    break;
                }
            }
            ///
            if (f){
                //cout << i << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());
    long long d = max(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            //bool fs = true , ft = true;
            unsigned long long cur;
            ///
            bool f = true;
            cur = hs[i - 1] * p[d - i];

            for (int j = 2*i - 1; j < sl; j+=i){
                if ((hs[j] - hs[j - i]) * p[d - j - 1] != cur){
                    f = false;
                    break;
                }
            }
            for (int j = 2*i - 1; j < tl; j+=i){
                if ((ht[j] - ht[j - i]) * p[d - j - 1] != cur){
                    f = false;
                    break;
                }
            }

            if (f) ans++;
            ///
        }
    }
    cout << ans << endl;

    return 0;
}

            /*///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if ((hs[j] - ht[j - i]) * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = hs[i - 1] * p[tl - i];
            if (cur != ht[i - 1] * p[tl - i]){
                ft = false;
            }
            for (int j = 2*i - 1; j < tl; j+=i){
                if ((ht[j] - ht[j - i]) * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }*/


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    long long hs[(int)(s.length())];
    long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if (hs[j] * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = ht[i - 1] * p[tl - i];
            for (int j = 2*i - 1 ; j < tl; j+=i){
                if (ht[j] * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs == true && ft == true){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100005];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = a.size()-1;
  else construct(b) , x = b.size()-1,swap(a,b);

  bool done = false;
  while(fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--,done = true;

  if(!done)x++;
  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
    return 0;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x) != now){
        cout << 0 <<endl;
        return 0;
      }
      i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}
/*
abababababababab
abababababababababababab
*/


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100005];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = a.size()-1;
  else construct(b) , x = b.size()-1,swap(a,b);

  while(fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x)!= now){
        cout << 0 <<endl;
        return 0;
      }else i+=x-1;
    }
  }
  int g = 1 , h = b.size()/x,alt = a.size()/x;
  int count = 0;
  while(g<=alt){
    if(h%g==0)
      count++;
    g++;
  }
  cout << count <<endl;
  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100010];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = fail[a.size()-1];
  else construct(b) , x = fail[b.size()-1],swap(a,b);

  if(a.size()==1){
    fore(i , b.size())
      if(a[0]!=b[i]){
        cout << 0 <<endl;
        return 0;
      }
    cout << 1 <<endl;
    return 0;
  }

  while( x>0 && fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(!x)x = a.size();
  else {
    now  = a.substr(0,x);
    fore(i , a.size()){
      if(a.substr(i , x)!=now){
        x = a.size();
        break;
      }
      i+=x-1;
    }
  }
  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
    return 0;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x) != now){
        cout << 0 <<endl;
        return 0;
      }
      i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}
/*
abababababababab
abababababababababababab
*/


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100010];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = fail[a.size()-1];
  else construct(b) , x = fail[b.size()-1],swap(a,b);

  if(a.size()==1){
    fore(i , b.size())
      if(a[0]!=b[i]){
        cout << 0 <<endl;
        return 0;
      }
    cout << 1 <<endl;
    return 0;
  }

  while( x>0 && fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(!x)x = a.size();
  else {
    now  = a.substr(0,x);
    fore(i , a.size()){
      if(a.substr(i , x)!=now){
        x = a.size();
        break;
      }
    }
  }
  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
    return 0;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x) != now){
        cout << 0 <<endl;
        return 0;
      }
      i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100005];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = a.size()-1;
  else construct(b) , x = b.size()-1,swap(a,b);

  while(fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x)!= now){
        cout << 0 <<endl;
        return 0;
      }else i+=x-1;
    }
  }
  int g = 1 , h = b.size()/x;
  int count = 0;
  while(h%g == 0){
    g++;
    count++;
  }
  cout << count <<endl;
  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100005];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = a.size()-1;
  else construct(b) , x = b.size()-1,swap(a,b);

  while(fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x)!= now){
        cout << 0 <<endl;
        return 0;
      }else i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}
/*
abababababababab
abababababababababababab
*/


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100010];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = fail[a.size()-1];
  else construct(b) , x = fail[b.size()-1],swap(a,b);

  if(a.size()==1){
    fore(i , b.size())
      if(a[0]!=b[i]){
        cout << 0 <<endl;
        return 0;
      }
    cout << 1 <<endl;
    return 0;
  }

  while( x>0 && fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(!x)x = a.size();
  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
    return 0;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x) != now){
        cout << 0 <<endl;
        return 0;
      }
      i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}
/*
abababababababab
abababababababababababab
*/


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100005];
void construct(string s){
  fail[0] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = a.size()-1;
  else construct(b) , x = b.size()-1,swap(a,b);

  while(fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(a.size()%x!=0 || b.size()%x!=0){
    if(a == b)
      cout << 1 <<endl;
    else cout << 0 <<endl;
    return 0;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x) != now){
        cout << 0 <<endl;
        return 0;
      }
      i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}
/*
abababababababab
abababababababababababab
*/


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 100000000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1000000009
#define MH2 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int > vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
int fail[100005];
void construct(string s){
  fail[1] = 0;
  lop(i , s.size()-1){
    int m = fail[i-1];
    while(m>0 && s[i]!=s[m])
      m = fail[m-1];
    if(s[i] == s[m])m++;
    fail[i+1] = m;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  string a,b,now;
  cin >> a >> b;
  int x;
  if(a.size()<b.size())
    construct(a),x = a.size();
  else construct(b) , x = b.size(),swap(a,b);

  while(fail[x]-fail[x-1] == 1 && fail[x]!=1)
    x--;

  if(a.size()%x!=0 || b.size()%x!=0){
    cout << 0 <<endl;
    return 0;
  }else {
    now  = a.substr(0,x);
    fore(i , b.size()){
      if(b.substr(i , x) != now){
        cout << 0 <<endl;
        return 0;
      }
      i+=x-1;
    }
  }
  int alt = x;
  int count = 0;
  while(x<=a.size()){
    if(b.size()%x==0 &&a.size()%x==0 )
      count++;
    x+=alt;
  }
  cout << count <<endl;
  return 0;
}
/*
abababababababab
abababababababababababab
*/


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[211111];
char b[211111];

int arr[1111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,1111111)
    arr[i]=1;
     fp(i,2,1111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,1111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb;

/*fs(i,ch)
if(a[i]!=b[i])
{
return 0;
}
*/

la=strlen(a);
lb=strlen(b);
fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
/*fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}
*/
return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
     strcat(a,b);
while(k>1)
{

    if(check(k)==1)
    ans++;
    k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d ",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[111111];
char b[111111];

int arr[111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,111111)
    arr[i]=1;
     fp(i,2,111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb,ans;
la=strlen(a);
lb=strlen(b);
fp(i,ch,min(la,lb),1)
{

   // printf("%c %c %c %c\n",a[i],a[i-ch],b[i],b[i-ch]);

    if(a[i]!=a[i-ch]||b[i]!=b[i-ch]||a[i]!=b[i])
   {

       return 0;
   }
}
fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}
fs(i,ch)
if(a[i]!=b[i])
{
return 0;
}

return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
while(k>1)
{

    if(check(k)==1)
    ans++;
    k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[211111];
char b[211111];

int arr[111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,111111)
    arr[i]=1;
     fp(i,2,111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb;

/*fs(i,ch)
if(a[i]!=b[i])
{
return 0;
}
*/

la=strlen(a);
lb=strlen(b);
fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
/*fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}
*/
return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
     strcat(a,b);
while(k>1)
{

    if(check(k)==1)
    ans++;
    k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[211111];
char b[211111];

int arr[1111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,1111111)
    arr[i]=1;
     fp(i,2,1111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,1111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb;

/*fs(i,ch)
if(a[i]!=b[i])
{
return 0;
}
*/

la=strlen(a);
lb=strlen(b);
fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
/*fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}
*/
return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
     strcat(a,b);
while(k>1)
{
    if(la%k==0&&lb%k==0)
    if(check(k)==1)
    ans++;
    k--;
   // k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[111111];
char b[111111];

int arr[111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,111111)
    arr[i]=1;
     fp(i,2,111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
//fs(i,ch)
//if(a[i]!=b[i])
//{
//return 0;
//}

fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}

return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
while(k>1)
{

    if(check(k)==1)
    ans++;
    k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[111111];
char b[111111];

int arr[111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,111111)
    arr[i]=1;
     fp(i,2,111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
fs(i,ch)
if(a[i]!=b[i])
{
return 0;
}

fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}

return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
while(k>1)
{

    if(check(k)==1)
    ans++;
    k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <utility>
    #include <vector>
    using namespace std;
using namespace std;

typedef pair<int,int> PII;
#define fp(i,a,b,c)  for(i=a;i<b;i+=c)
#define fn(i,a,b,c)  for(i=a;i>b;i-=c)
#define fs(i,a)      for(i=0;i<a;i++)
#define sci(a)       scanf("%d",&a)
#define sci2(a,b)       scanf("%d%d",&a,&b)
#define pf(a)         printf("%d ",a)
#define pf2(a,b)         printf("%d %d\n",a,b)

char a[11111];
char b[11111];

int arr[111111];

int init()
{
    scanf("%s",a);
    scanf("%s",b);
int i,j;
    fs(i,111111)
    arr[i]=1;
     fp(i,2,111111,1)
     {
         if(arr[i]==1)
         {
             fp(j,i,111111,i)
             arr[j]=i;
         }
     }
    return 0;
}
int gcd(int a,int b)
{
    return a?gcd(b%a,a):b;
}
int check(int ch)
{
    int i,j,k,l,la,lb,ans;
la=strlen(a);
lb=strlen(b);
fp(i,ch,min(la,lb),1)
{

   // printf("%c %c %c %c\n",a[i],a[i-ch],b[i],b[i-ch]);

    if(a[i]!=a[i-ch]||b[i]!=b[i-ch]||a[i]!=b[i])
   {

       return 0;
   }
}
fp(i,ch,la,1)
{

    if(a[i]!=a[i-ch])
    return 0;
}
fp(i,ch,lb,1)
{
    if(b[i]!=b[i-ch])
    return 0;
}
fs(i,ch)
if(a[i]!=b[i])
{
return 0;
}

return 1;

}

int ans()
{
    int i,j,k,l,la,lb;
la=strlen(a);
lb=strlen(b);
     k=gcd(la,lb);
     int ans=0;
while(k>1)
{

    if(check(k)==1)
    ans++;
    k/=arr[k];

}
if(check(1)==1)
    ans++;

pf(ans);
return 0;

}
int main()
{

    init();

    ans();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

const int N = 200000;

char a[N], b[N], tmp[N];
int next[N];
bool vis[N];

/*void KMP(char* t, char* p)*/
//{
	//int n = strlen(t+1);
	//int m = strlen(p+1);

	//compute_prefix(p);

	//q = 0;
	//for (int i = 1; i <= n; i++)
	//{
		//while (q > 0 && p[q+1] != t[i])
			//q = next[q];
		//if (p[q+1] == T[i])
			//q++;
		//if (q==m)
			//q = next[q];
	//}
/*}*/

int compute_prefix(char *p)
{
	int m = strlen(p+1);
	next[1] = 0;
	int k = 0;
	for (int q = 2; q <= m; q++)
	{
		while (k > 0 && p[k+1] != p[q])
			k = next[k];
		if (p[k+1] == p[q])
			k++;
		next[q] = k;
	}
}
int main()
{
	//freopen("test.txt", "r", stdin);

	while (scanf("%s%s", a+1, b+1) != EOF)
	{
		int len_a = strlen(a+1);
		int len_b = strlen(b+1);

		int cnt_a = strlen(a+1);
		int cnt_b = strlen(b+1);

		if (len_a < len_b)
		{
			strcpy(tmp, a+1);
			strcpy(a+1, b+1);
			strcpy(b+1, tmp);
			swap(len_a, len_b);
			swap(cnt_a, cnt_b);
		}

		//int data1[N], data2[N];
		//int cnt_1 = 0, cnt_2 = 0;
        int data[N];
		int pos = 0;
		/*compute_prefix(a);*/
		//if (len_a%next[len_a] != 0)
			//printf("0");
		/*else*/
		memset(vis, 0, sizeof(vis));
		{
			vis[len_a] = 1;
			while (1)
			{
				compute_prefix(a);
				if (next[len_a] == 0 || len_a%(len_a-next[len_a]) != 0)
					break;
				a[len_a-next[len_a]+1] = 0;

				for (int i = len_a-next[len_a]; i <= len_a; i += len_a-next[len_a])
					if (cnt_a % i == 0)
						vis[i] = 1;
				len_a = len_a-next[len_a];

				//vis[len_a] = 1;
			}

			int cnt = 1;
			set<int> data;
			data.insert(len_b);
			while (1)
			{
				compute_prefix(b);
				if (next[len_b] == 0 || len_b%(len_b-next[len_b]) != 0)
					break;
				b[len_b-next[len_b]+1] = 0;
				for (int i = len_b-next[len_b]; i <= len_b; i += len_b-next[len_b])
					if (cnt_b % i == 0)
					 data.insert(i);
				len_b = len_b - next[len_b];
				//data[pos++] = len_b;
			}

		    if (len_a == len_b && strcmp(a+1, b+1) == 0)
			{
				long long ans = 0;
				set<int>::iterator it = data.begin();
				while (it != data.end())
				{
					int t = *it;
					if (cnt_a%t == 0 && vis[t])
						ans++;
					it++;
				}
				cout << ans << endl;
			}
			else
				cout << 0 << endl;

		}
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 200000;

char a[N], b[N], tmp[N];
int next[N];
bool vis[N];

/*void KMP(char* t, char* p)*/
//{
	//int n = strlen(t+1);
	//int m = strlen(p+1);

	//compute_prefix(p);

	//q = 0;
	//for (int i = 1; i <= n; i++)
	//{
		//while (q > 0 && p[q+1] != t[i])
			//q = next[q];
		//if (p[q+1] == T[i])
			//q++;
		//if (q==m)
			//q = next[q];
	//}
/*}*/

int compute_prefix(char *p)
{
	int m = strlen(p+1);
	next[1] = 0;
	int k = 0;
	for (int q = 2; q <= m; q++)
	{
		while (k > 0 && p[k+1] != p[q])
			k = next[k];
		if (p[k+1] == p[q])
			k++;
		next[q] = k;
	}
}
int main()
{
	//freopen("test.txt", "r", stdin);

	while (scanf("%s%s", a+1, b+1) != EOF)
	{
		int len_a = strlen(a+1);
		int len_b = strlen(b+1);

		int cnt_a = strlen(a+1);
		int cnt_b = strlen(b+1);

		if (len_a < len_b)
		{
			strcpy(tmp, a+1);
			strcpy(a+1, b+1);
			strcpy(b+1, tmp);
			swap(len_a, len_b);
		}

		//int data1[N], data2[N];
		//int cnt_1 = 0, cnt_2 = 0;
        int data[N];
		int pos = 0;
		/*compute_prefix(a);*/
		//if (len_a%next[len_a] != 0)
			//printf("0");
		/*else*/
		memset(vis, 0, sizeof(vis));
		{
			vis[len_a] = 1;
			while (1)
			{
				compute_prefix(a);
				if (next[len_a] == 0 || len_a%(len_a-next[len_a]) != 0)
					break;
				a[len_a-next[len_a]+1] = 0;

				for (int i = len_a-next[len_a]; i <= len_a; i += len_a-next[len_a])
					vis[i] = 1;
				len_a = len_a-next[len_a];

				//vis[len_a] = 1;
			}

			int cnt = 1;
			data[pos++] = len_b;
			while (1)
			{
				compute_prefix(b);
				if (next[len_b] == 0 || len_b%(len_b-next[len_b]) != 0)
					break;
				b[len_b-next[len_b]+1] = 0;
				for (int i = len_b-next[len_b]; i <= len_b; i += len_b-next[len_b])
					 data[pos++] = i;
				len_b = len_b - next[len_b];
				//data[pos++] = len_b;
			}

		    if (len_a == len_b && strcmp(a+1, b+1) == 0)
			{
				int ans = 0;
				for (int i = 0; i < pos; i++)
					if (cnt_a%data[i] == 0 && vis[data[i]])
						ans++;
				cout << ans << endl;
			}
			else
				cout << 0 << endl;

		}
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

const int N = 200000;

char a[N], b[N], tmp[N];
int next[N];
bool vis[N];

/*void KMP(char* t, char* p)*/
//{
	//int n = strlen(t+1);
	//int m = strlen(p+1);

	//compute_prefix(p);

	//q = 0;
	//for (int i = 1; i <= n; i++)
	//{
		//while (q > 0 && p[q+1] != t[i])
			//q = next[q];
		//if (p[q+1] == T[i])
			//q++;
		//if (q==m)
			//q = next[q];
	//}
/*}*/

int compute_prefix(char *p)
{
	int m = strlen(p+1);
	next[1] = 0;
	int k = 0;
	for (int q = 2; q <= m; q++)
	{
		while (k > 0 && p[k+1] != p[q])
			k = next[k];
		if (p[k+1] == p[q])
			k++;
		next[q] = k;
	}
}
int main()
{
	//freopen("test.txt", "r", stdin);

	while (scanf("%s%s", a+1, b+1) != EOF)
	{
		int len_a = strlen(a+1);
		int len_b = strlen(b+1);

		int cnt_a = strlen(a+1);
		int cnt_b = strlen(b+1);

		if (len_a < len_b)
		{
			strcpy(tmp, a+1);
			strcpy(a+1, b+1);
			strcpy(b+1, tmp);
			swap(len_a, len_b);
		}

		//int data1[N], data2[N];
		//int cnt_1 = 0, cnt_2 = 0;
        int data[N];
		int pos = 0;
		/*compute_prefix(a);*/
		//if (len_a%next[len_a] != 0)
			//printf("0");
		/*else*/
		memset(vis, 0, sizeof(vis));
		{
			vis[len_a] = 1;
			while (1)
			{
				compute_prefix(a);
				if (next[len_a] == 0 || len_a%(len_a-next[len_a]) != 0)
					break;
				a[len_a-next[len_a]+1] = 0;

				for (int i = len_a-next[len_a]; i <= len_a; i += len_a-next[len_a])
					if (cnt_a % i == 0)
						vis[i] = 1;
				len_a = len_a-next[len_a];

				//vis[len_a] = 1;
			}

			int cnt = 1;
			set<int> data;
			data.insert(len_b);
			while (1)
			{
				compute_prefix(b);
				if (next[len_b] == 0 || len_b%(len_b-next[len_b]) != 0)
					break;
				b[len_b-next[len_b]+1] = 0;
				for (int i = len_b-next[len_b]; i <= len_b; i += len_b-next[len_b])
					if (cnt_b % i == 0)
					 data.insert(i);
				len_b = len_b - next[len_b];
				//data[pos++] = len_b;
			}

		    if (len_a == len_b && strcmp(a+1, b+1) == 0)
			{
				long long ans = 0;
				set<int>::iterator it = data.begin();
				while (it != data.end())
				{
					int t = *it;
					if (cnt_a%t == 0 && vis[t])
						ans++;
					it++;
				}
				cout << ans << endl;
			}
			else
				cout << 0 << endl;

		}
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 200000;

char a[N], b[N], tmp[N];
int next[N];
bool vis[N];

/*void KMP(char* t, char* p)*/
//{
	//int n = strlen(t+1);
	//int m = strlen(p+1);

	//compute_prefix(p);

	//q = 0;
	//for (int i = 1; i <= n; i++)
	//{
		//while (q > 0 && p[q+1] != t[i])
			//q = next[q];
		//if (p[q+1] == T[i])
			//q++;
		//if (q==m)
			//q = next[q];
	//}
/*}*/

int compute_prefix(char *p)
{
	int m = strlen(p+1);
	next[1] = 0;
	int k = 0;
	for (int q = 2; q <= m; q++)
	{
		while (k > 0 && p[k+1] != p[q])
			k = next[k];
		if (p[k+1] == p[q])
			k++;
		next[q] = k;
	}
}
int main()
{
	//freopen("test.txt", "r", stdin);

	while (scanf("%s%s", a+1, b+1) != EOF)
	{
		int len_a = strlen(a+1);
		int len_b = strlen(b+1);

		int cnt_a = strlen(a+1);
		int cnt_b = strlen(b+1);

		if (len_a < len_b)
		{
			strcpy(tmp, a+1);
			strcpy(a+1, b+1);
			strcpy(b+1, tmp);
			swap(len_a, len_b);
		}

		//int data1[N], data2[N];
		//int cnt_1 = 0, cnt_2 = 0;
        int data[N];
		int pos = 0;
		/*compute_prefix(a);*/
		//if (len_a%next[len_a] != 0)
			//printf("0");
		/*else*/
		memset(vis, 0, sizeof(vis));
		{
			vis[len_a] = 1;
			while (1)
			{
				compute_prefix(a);
				if (next[len_a] == 0 || len_a%(len_a-next[len_a]) != 0)
					break;
				a[len_a-next[len_a]+1] = 0;

				for (int i = len_a-next[len_a]; i <= len_a; i += len_a-next[len_a])
					vis[i] = 1;
				len_a = len_a-next[len_a];

				//vis[len_a] = 1;
			}

			int cnt = 1;
			data[pos++] = len_b;
			while (1)
			{
				compute_prefix(b);
				if (next[len_b] == 0 || len_b%(len_b-next[len_b]) != 0)
					break;
				b[len_b-next[len_b]+1] = 0;
				len_b = len_b - next[len_b];
				data[pos++] = len_b;
			}

		    if (len_a == len_b && strcmp(a+1, b+1) == 0)
			{
				int ans = 0;
				for (int i = 0; i < pos; i++)
					if (cnt_a%data[i] == 0 && vis[data[i]])
						ans++;
				cout << ans << endl;
			}
			else
				cout << 0 << endl;

		}
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

const int N = 200000;

char a[N], b[N], tmp[N];
int next[N];
bool vis[N];

/*void KMP(char* t, char* p)*/
//{
	//int n = strlen(t+1);
	//int m = strlen(p+1);

	//compute_prefix(p);

	//q = 0;
	//for (int i = 1; i <= n; i++)
	//{
		//while (q > 0 && p[q+1] != t[i])
			//q = next[q];
		//if (p[q+1] == T[i])
			//q++;
		//if (q==m)
			//q = next[q];
	//}
/*}*/

int compute_prefix(char *p)
{
	int m = strlen(p+1);
	next[1] = 0;
	int k = 0;
	for (int q = 2; q <= m; q++)
	{
		while (k > 0 && p[k+1] != p[q])
			k = next[k];
		if (p[k+1] == p[q])
			k++;
		next[q] = k;
	}
}
int main()
{
	//freopen("test.txt", "r", stdin);

	while (scanf("%s%s", a+1, b+1) != EOF)
	{
		int len_a = strlen(a+1);
		int len_b = strlen(b+1);

		int cnt_a = strlen(a+1);
		int cnt_b = strlen(b+1);

		if (len_a < len_b)
		{
			strcpy(tmp, a+1);
			strcpy(a+1, b+1);
			strcpy(b+1, tmp);
			swap(len_a, len_b);
		}

		//int data1[N], data2[N];
		//int cnt_1 = 0, cnt_2 = 0;
        int data[N];
		int pos = 0;
		/*compute_prefix(a);*/
		//if (len_a%next[len_a] != 0)
			//printf("0");
		/*else*/
		memset(vis, 0, sizeof(vis));
		{
			vis[len_a] = 1;
			while (1)
			{
				compute_prefix(a);
				if (next[len_a] == 0 || len_a%(len_a-next[len_a]) != 0)
					break;
				a[len_a-next[len_a]+1] = 0;

				for (int i = len_a-next[len_a]; i <= len_a; i += len_a-next[len_a])
					vis[i] = 1;
				len_a = len_a-next[len_a];

				//vis[len_a] = 1;
			}

			int cnt = 1;
			set<int> data;
			data.insert(len_b);
			while (1)
			{
				compute_prefix(b);
				if (next[len_b] == 0 || len_b%(len_b-next[len_b]) != 0)
					break;
				b[len_b-next[len_b]+1] = 0;
				for (int i = len_b-next[len_b]; i <= len_b; i += len_b-next[len_b])
					 data.insert(i);
				len_b = len_b - next[len_b];
				//data[pos++] = len_b;
			}

		    if (len_a == len_b && strcmp(a+1, b+1) == 0)
			{
				long long ans = 0;
				set<int>::iterator it = data.begin();
				while (it != data.end())
				{
					int t = *it;
					if (cnt_a%t == 0 && vis[t])
						ans++;
					it++;
				}
				cout << ans << endl;
			}
			else
				cout << 0 << endl;

		}
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

const int N = 200000;

char a[N], b[N], tmp[N];
int next[N];
bool vis[N];

/*void KMP(char* t, char* p)*/
//{
	//int n = strlen(t+1);
	//int m = strlen(p+1);

	//compute_prefix(p);

	//q = 0;
	//for (int i = 1; i <= n; i++)
	//{
		//while (q > 0 && p[q+1] != t[i])
			//q = next[q];
		//if (p[q+1] == T[i])
			//q++;
		//if (q==m)
			//q = next[q];
	//}
/*}*/

int compute_prefix(char *p)
{
	int m = strlen(p+1);
	next[1] = 0;
	int k = 0;
	for (int q = 2; q <= m; q++)
	{
		while (k > 0 && p[k+1] != p[q])
			k = next[k];
		if (p[k+1] == p[q])
			k++;
		next[q] = k;
	}
}
int main()
{
	//freopen("test.txt", "r", stdin);

	while (scanf("%s%s", a+1, b+1) != EOF)
	{
		int len_a = strlen(a+1);
		int len_b = strlen(b+1);

		int cnt_a = strlen(a+1);
		int cnt_b = strlen(b+1);

		if (len_a < len_b)
		{
			strcpy(tmp, a+1);
			strcpy(a+1, b+1);
			strcpy(b+1, tmp);
			swap(len_a, len_b);
		}

		//int data1[N], data2[N];
		//int cnt_1 = 0, cnt_2 = 0;
        int data[N];
		int pos = 0;
		/*compute_prefix(a);*/
		//if (len_a%next[len_a] != 0)
			//printf("0");
		/*else*/
		memset(vis, 0, sizeof(vis));
		{
			vis[len_a] = 1;
			while (1)
			{
				compute_prefix(a);
				if (next[len_a] == 0 || len_a%(len_a-next[len_a]) != 0)
					break;
				a[len_a-next[len_a]+1] = 0;

				for (int i = len_a-next[len_a]; i <= len_a; i += len_a-next[len_a])
					vis[i] = 1;
				len_a = len_a-next[len_a];

				//vis[len_a] = 1;
			}

			int cnt = 1;
			set<int> data;
			data.insert(len_b);
			while (1)
			{
				compute_prefix(b);
				if (next[len_b] == 0 || len_b%(len_b-next[len_b]) != 0)
					break;
				b[len_b-next[len_b]+1] = 0;
				for (int i = len_b-next[len_b]; i <= len_b; i += len_b-next[len_b])
					 data.insert(i);
				len_b = len_b - next[len_b];
				//data[pos++] = len_b;
			}

		    if (len_a == len_b && strcmp(a+1, b+1) == 0)
			{
				int ans = 0;
				set<int>::iterator it = data.begin();
				while (it != data.end())
				{
					int t = *it;
					if (cnt_a%t == 0 && vis[t])
						ans++;
					it++;
				}
				cout << ans << endl;
			}
			else
				cout << 0 << endl;

		}
	}
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j;
    for(i=1,j=pval[0]=0;i<len;i++)
    {
        while(a[j]==a[i])
        {
            pval[i]=pval[i-1]+1;
            i++;
            j++;
        }
        pval[i]=j=0;
    }
    //for(i=0;i<len;i++) printf("%d: %d\n",i,pval[i]);
    i=len-pval[len-1];
    if(i<1) return -1;
    if(len%i) return -1;
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x!=y||x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j,prev;
    for(i=1,j=pval[0]=0;i<len;)
    {
        j=0;while(a[j]!=a[i]&&i<len) i++,pval[i]=0;
        while(a[j]==a[i]&&i<len)
        {
            if(j) prev=pval[i-1];else prev=0;
            pval[i]=prev+1;
            i++;
            j++;
        }
    }
    i=len-pval[len-1];
    if(i<1) return 0;
    if(len%i) return len;
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x!=y||x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j,prev;
    for(i=1,j=pval[0]=0;i<len;)
    {
        j=0;while(a[j]!=a[i]) i++,pval[i]=0;
        while(a[j]==a[i]&&i<len)
        {
            if(j) prev=pval[i-1];else prev=0;
            pval[i]=prev+1;
            i++;
            j++;
        }
    }
    i=len-pval[len-1];
    if(i<1) return 0;
    if(len%i) return len;
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x!=y||x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j;
    for(i=1,j=pval[0]=0;i<len;i++)
    {
        while(a[j]==a[i])
        {
            pval[i]=pval[i-1]+1;
            i++;
            j++;
        }
        pval[i]=j=0;
    }
    i=len-pval[len-1];
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x!=y||x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j;
    for(i=1,j=pval[0]=0;i<len;i++)
    {
        while(a[j]==a[i])
        {
            pval[i]=pval[i-1]+1;
            i++;
            j++;
        }
        pval[i]=j=0;
    }
    //for(i=0;i<len;i++) printf("%d: %d\n",i,pval[i]);
    i=len-pval[len-1];
    if(i<1) return 0;
    if(len%i) return len;
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x!=y||x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j,prev;
    for(i=1,j=pval[0]=0;i<len;)
    {
        j=0;while(a[j]!=a[i]) i++;
        while(a[j]==a[i]&&i<len)
        {
            if(j) prev=pval[i-1];else prev=0;
            pval[i]=prev+1;
            i++;
            j++;
        }
    }
    //for(i=0;i<len;i++) printf("%d: %d\n",i,pval[i]);
    i=len-pval[len-1];
    if(i<1) return 0;
    if(len%i) return len;
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x!=y||x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


/*This is by Technical Bangla from University of Dhaka*/
#include <bits/stdc++.h>
using namespace std;

#define pi acos(-1.0)
#define e 2.7182818284590451
#define eps 1e-12
#define in_d(x) scanf("%d",&x)
#define nl printf("\n")
#define MAX 100100
#define Mod 1000000007
#define inf 1e18
#define UND 1e17
#define MOD(a,m) ((a)%(m)+(m))%(m)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
typedef long long int ll;
typedef unsigned long long int llu;

template <class T> T sqr(T x) {return x*x;}
template <class T> T distsqr(T x,T y,T a,T b) {return sqr(x-a)+sqr(y-b);}
double cosine_angle(double a,double b,double c) {return (double)(sqr(a)+sqr(b)-sqr(c))/((double)2.0*a*b);}

template <class T> T Maximum(T a, T b) {return a>b?a:b;}
template <class T> T Minimum(T a, T b) {return a<b?a:b;}
template <class T> T GCD(T a, T b) {if(!b) return a;return GCD(b,a%b);}
template <class T> void SWAP(T &a, T &b) {T temp=a;a=b;b=temp;return ;}
template <class T> T sign(T a) {return a<0?-1:1;}
template <class T> T BigMod(T a,T n,T mod) {if(!n) return (T)1%mod;ll power=BigMod(a,n>>1,mod);power%=mod;power*=power;power%=mod;if(n&1) power*=a%mod,power%=mod;return power;}
template <class T> T ExtendedEuclid(T a,T b,T c) {if(!a) return 0;return (b*ExtendedEuclid(b%a,a,-c)+c)/a;}
template <class T> T ModInverse(T a,T m) {return MOD(ExtendedEuclid(a,m,(T)GCD(a,m)),m);}

int pval[MAX];

int FindingStrDivisor(char *a,int len)
{
    int i,j;
    for(i=1,j=pval[0]=0;i<len;i++)
    {
        while(a[j]==a[i])
        {
            pval[i]=pval[i-1]+1;
            i++;
            j++;
        }
        pval[i]=j=0;
    }
    //for(i=0;i<len;i++) printf("%d: %d\n",i,pval[i]);
    i=len-pval[len-1];
    if(i<1) return 0;
    if(len%i) return 0;
    return i;
}

char str[2][MAX];

int Solving(char *a,char *b)
{
    int alen=strlen(a),blen=strlen(b);
    int i,c,x=FindingStrDivisor(a,alen),y=FindingStrDivisor(b,blen);
    if(x<1||y<1) return 0;
    for(i=0;i<x;i++)
    {
        if(a[i]==b[i]);else return 0;
    }
    x=GCD(alen/x,blen/y);
    for(i=1,c=0;i<x+1;i++) if(x%i==0) c++;
    return c;
}

int main()
{
    scanf("%s %s",str[0],str[1]);
    printf("%d\n",Solving(str[0],str[1]));
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=abs(T1[i+j]-T1[j]);

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=abs(T2[i+j]-T1[j]);

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

   // freopen("expedition.in","r",stdin);
    //freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int gam (int x) {

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++) {
			if (T1[i+j]!=T1[j])
				return 0;

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++) {
			if (T2[i+j]!=T1[j])
				return 0;

return 1;
}

int main () {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S>1)
		return 0;
	else
		return 1;

}

int main () {

    //freopen("expedition.in","r",stdin);
    //freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

    //freopen("expedition.in","r",stdin);
    //freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length()-1;
	B=T2.length();

	(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

    freopen("expedition.in","r",stdin);
    freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	//(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int gam (int x) {
	for (int i=0; i<A; i++)
		if (T1[i]!=T1[i%x])
			return 0;

	for (int i=0; i<B; i++)
		if (T2[i]!=T1[i%x])
			return 0;

	return 1;
}

int main () {

   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

    //freopen("expedition.in","r",stdin);
    //freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	if (T1[A]==' ')
		A--;
	B=T2.length();
	if (T2[B]==' ')
		B--;

	(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

    //freopen("expedition.in","r",stdin);
    //freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	//(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S>1)
		return 0;
	else
		return 1;

}

int main () {

   // freopen("expedition.in","r",stdin);
   // freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int gam (int x) {

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			if (T1[i+j]!=T1[j])
				return 0;

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			if (T2[i+j]!=T1[j])
				return 0;

return 1;
}

int main () {

   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int NOD (int a, int b) {
	if (b%a==0)
		return a;
	NOD(b%a,a);
}

int gam (int x) {

	int S=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T1[i+j]-T1[j];

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++)
			S+=T2[i+j]-T1[j];

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

    //freopen("expedition.in","r",stdin);
   // freopen("expedition.out","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	nod=A;

	if (A>B)
		nod=B;
	else
		nod=A;

	//(A>B) ? nod=NOD(B,A) : nod=NOD(A,B);

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>

using namespace std;

string T1,T2;
int A,B,nod,Sum=0;

int gam (int x) {

	int S=0,X=0;

	for (int i=0; i<A/x; i+=x)
		for (int j=0; j<x; j++) {
			X=T1[i+j]-T1[j];
			if (X<0)
				X=-X;
			S+=X;
		}

	for (int i=0; i<B/x; i+=x)
		for (int j=0; j<x; j++) {
			X=T2[i+j]-T1[j];
			if (X<0)
				X=-X;
			S+=X;
		}

	if (S==0)
		return 1;
	else
		return 0;

}

int main () {

   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

	getline(cin,T1);
	getline(cin,T2);

	A=T1.length();
	B=T2.length();

	if (A>B)
		nod=B;
	else
		nod=A;

	for (int k=1; k<=nod; k++)
		if ((A%k==0)&&(B%k==0))
			Sum+=gam(k);

	cout << Sum;

	return 0;
}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
int n1,n2;
int min_len;
string str1,str2;

int ans=0;

void check(int ind){
    //cout<<"  "<<ind<<endl;
    int i;

    if(n1%ind||n2%ind)  return ;
    rep(i,0,n1){
        if(str1[i%ind]!=str1[i])    return ;

    }

    rep(i,0,n2){
        if(str2[i%ind]!=str2[i])    return ;

    }

    ans++;
}

void solve(){
    int i;
    rep(i,1,sqrt(n1)+1){
        if(n1%i==0){
           // cout<<"i= "<<i<<endl;
            check(i);

            if(n1/i!=i) {
                check(n1/i);
            }

        }

    }

}

int main(){
    std::ios::sync_with_stdio(false);

    cin>>str1>>str2;

    n1=str1.length();
    n2=str2.length();
     solve();

    cout<<ans<<endl;

return 0;

}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
string s1, s2;
int l1, l2;
int chk(int len){
    int i;
    for(i=0;i<l1;i++){
        if(s1[i%len] != s1[i])
            return 0;
    }
    for(i=0;i<l2;i++){
        if(s1[i%len] != s2[i])
            return 0;
    }
    return 1;
}
int main(){
    cin  >> s1 >> s2;
    l1 = s1.size(), l2= s2.size();
    int i, cnt = 0;
    for(i=1;i*i<=l1;i++){
        if(l1 %i == 0){
            int f1 = i;
            if(l2 %f1 == 0){
                cnt += chk(f1);
            }
            if(l1/i != i){
                int f2 = l1/i;
                if(l2 % f2 == 0)
                    cnt += chk(f2);
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
int n1,n2;
int min_len;
string str1,str2;

int ans=0;

void check(int ind){

    int i;

    if(n1%ind||n2%ind)  return ;
    rep(i,0,n1){
        if(str1[i%ind]!=str1[i])    return ;

    }

    rep(i,0,n2){
        if(str1[i%ind]!=str2[i])    return ;

    }
     cout<<"  "<<ind<<endl;
    ans++;
}

void solve(){
    int i;
    rep(i,1,sqrt(n1)+1){
        if(n1%i==0){
           // cout<<"i= "<<i<<endl;
            check(i);

            if(n1/i!=i) {
                check(n1/i);
            }

        }

    }

}

int main(){
    std::ios::sync_with_stdio(false);

    cin>>str1>>str2;

    n1=str1.length();
    n2=str2.length();
     solve();

    cout<<ans<<endl;

return 0;

}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
int n1,n2;
int min_len;
string str1,str2;

int ans=0;

void check(int ind){
    //cout<<"  "<<ind<<endl;
    int i;
    if(ind>n1)  return ;
    rep(i,0,n1){
        if(str1[i%ind]!=str1[i])    return ;

    }

    if(ind>n2)  return;
    rep(i,0,n2){
        if(str2[i%ind]!=str2[i])    return ;

    }

    ans++;
}

void solve(){
    int i;
    rep(i,1,sqrt(n1)+1){
        if(n1%i==0){
           // cout<<"i= "<<i<<endl;
            check(i);

            if(n1/i!=i) {
                check(n1/i);
            }

        }

    }

}

int main(){
    std::ios::sync_with_stdio(false);

    cin>>str1>>str2;

    n1=str1.length();
    n2=str2.length();
     solve();

    cout<<ans<<endl;

return 0;

}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
int n1,n2;
int min_len;
string str1,str2;

int ans=0;

void check(int ind){

    int i;

    if(n1%ind||n2%ind)  return ;
    rep(i,0,n1){
        if(str1[i%ind]!=str1[i])    return ;

    }

    rep(i,0,n2){
        if(str1[i%ind]!=str2[i])    return ;

    }
    // cout<<"  "<<ind<<endl;
    ans++;
}

void solve(){
    int i;
    rep(i,1,sqrt(n1)+1){
        if(n1%i==0){
           // cout<<"i= "<<i<<endl;
            check(i);

            if(n1/i!=i) {
                check(n1/i);
            }

        }

    }

}

int main(){
    std::ios::sync_with_stdio(false);

    cin>>str1>>str2;

    n1=str1.length();
    n2=str2.length();
     solve();

    cout<<ans<<endl;

return 0;

}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
int n1,n2;
int min_len;
string str1,str2;

int ans=0;

void check(int ind){

    int i;

    if(n1%ind||n2%ind)  return ;
    rep(i,0,n1){
        if(str1[i%ind]!=str1[i])    return ;

    }

    rep(i,0,n2){
        if(str1[i%ind]!=str2[i])    return ;

    }
    // cout<<"  "<<ind<<endl;
    ans++;
}

void solve(){
    int i;
    rep(i,1,sqrt(n1)+1){
        if(n1%i==0){
           // cout<<"i= "<<i<<endl;
            if(n1/i!=1)
            check(i);

            if(n1/i!=i) {
                check(n1/i);
            }

        }

    }

}

int main(){
    std::ios::sync_with_stdio(false);

    cin>>str1>>str2;

    n1=str1.length();
    n2=str2.length();
     solve();

    cout<<ans<<endl;

return 0;

}


#include<bits/stdc++.h>
    #include<string>
    using namespace std;
    template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
    template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
    #define traverse(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
    #define         mp(x, y) make_pair(x, y)
    #define         SIZE(c) (int)c.size()
    #define         pb(x) push_back(x)
    //#define       map<char,int>::iterator it;
    #define         ff first
    #define         ss second
    #define         ll long long
    #define         ld long double
    #define         pii pair< int, int >
    #define         psi pair< string, int >
    #define         p(n) printf("%d\n",n)
    #define         p64(n) printf("%lld\n",n)
    #define         s(n) scanf("%d",&n)
    #define         s64(n) scanf("%I64d",&n)
    #define         rep(i,a,b) for(i=a;i<b;i++)
    #define         MOD (100000000LL)

long long pwr(long long a,long long b)
{
  if(b==0)
    return 1;
  long long temp=pwr(a,b/2);
  temp=(temp*temp);
  if(b&1)
    temp=(temp*a);
  return temp;
}

    ///////////////////////////////////////////////////////
int n1,n2;
int min_len;
string str1,str2;

int ans=0;

void check(int ind){
    //cout<<"  "<<ind<<endl;
    int i;
    if(ind>n1)  return ;
    if(n1%ind)  return ;
    rep(i,0,n1){
        if(str1[i%ind]!=str1[i])    return ;

    }

    if(ind>n2)  return;
    rep(i,0,n2){
        if(str2[i%ind]!=str2[i])    return ;

    }

    ans++;
}

void solve(){
    int i;
    rep(i,1,sqrt(n1)+1){
        if(n1%i==0){
           // cout<<"i= "<<i<<endl;
            check(i);

            if(n1/i!=i) {
                check(n1/i);
            }

        }

    }

}

int main(){
    std::ios::sync_with_stdio(false);

    cin>>str1>>str2;

    n1=str1.length();
    n2=str2.length();
     solve();

    cout<<ans<<endl;

return 0;

}


#include<cstdio>
#include<cstring>

char a[100050];
char b[100050];
int p[100050];
int m,n;
int l1,l2;

void getp(char b[],int m){
    p[1]=0;
    int i,j=0;
    for(i=2;i<=m;i++){
        while(j>0&&b[j+1]!=b[i]) j=p[j];
        if(b[j+1]==b[i]) j+=1;
        p[i]=j;
    }
}

int Min(int a,int b)
{
    if(a<b) return a;
    return b;
}

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main(){
    int x1,x2;
    int i;
   while(scanf("%s%s",a+1,b+1)!=EOF)
   {
       m=l1=strlen(a+1);
       getp(a,l1);
       if(m%(m-p[m])==0) x1=m/(m-p[m]);
       else x1=1;
       m=l2=strlen(b+1);
       getp(b,l2);
       if(m%(m-p[m])==0) x2=m/(m-p[m]);
       else x2=1;
      // printf("%d  %d\n",x1,x2);
       if(l1/x1==l2/x2)
       {
        int t=Min(l1/x1,l2/x2);
            for(i=1;i<=t;i++)
                if(a[i]!=b[i])
                    break;
            printf("%d %d\n",i,t);
            if(i<=t)
                puts("0");
            else
            {
                int ans=gcd(x1,x2);
                printf("%d\n",ans);
            }
       }
       else
           puts("0");

   }
   return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
//  printf("%d  %d  gao\n",len,next[len-1]);
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
        int ans=0;
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            if(!flag)
            {
                int g1=len_s/c1 ,g2=len_t/c2;
                for(i=1;i<=g1 && i<=g2;i++)
                    if(g1%i==0 && g2%i==0)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else
        {
                if(len_s%len_t==0)
        {
            for(i=0;i<len_s;i++)
                if(s[i]!=s[i%len_t])
                    break;
            if(i<len_s) ans++;
        }
        else if(len_t%len_s==0)
        {
            for(i=0;i<len_t;i++)
                if(s[i]!=s[i%len_s])
                    break;
            if(i<len_t) ans++;
        }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
//  printf("%d  %d  gao\n",len,next[len-1]);
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
        int ans=0;
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            if(!flag)
            {
                int g1=len_s/c1 ,g2=len_t/c2;
                for(i=1;i<=g1 && i<=g2;i++)
                    if(g1%i==0 && g2%i==0)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else
        {

            if(len_s%len_t==0)
            {//puts("ffff");
                for(i=0;i<len_s;i++)
                    if(s[i]!=t[i%len_t])
                        break;
            //  printf("%d\n",i);
                if(i>=len_s) ans++;
            }
            else if(len_t%len_s==0)
            {
                for(i=0;i<len_t;i++)
                    if(t[i]!=s[i%len_s])
                        break;
                if(i>=len_t) ans++;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
//  printf("%d  %d  gao\n",len,next[len-1]);
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
        int ans=0;
        if(len_s%len_t==0)
        {
            for(i=0;i<len_s;i++)
                if(s[i]!=s[i%len_t])
                    break;
            if(i<len_s) ans++;
        }
        else if(len_t%len_s==0)
        {
            for(i=0;i<len_t;i++)
                if(s[i]!=s[i%len_s])
                    break;
            if(i<len_t) ans++;
        }
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            if(!flag)
            {
                int g1=len_s/c1 ,g2=len_t/c2;
                for(i=1;i<g1 && i<g2;i++)
                    if(g1%i==0 && g2%i==0)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else  printf("%d\n",ans);
    }
    return 0;
}