Language: C++

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
int dp[4001];
ll pat[4001];
ll tx[4001];
ll hash[4001];

bool C(int f,int t){
	int len=t-f;
	vector<int> ve;
	for(int g=2;g*g<=len;g++){
		if(len%g==0){
			ve.push_back(g);
			ve.push_back(len/g);
		}
	}
	for(int i=0;i<ve.size();i++){
		int v=ve[i];
		ll base=(hash[f+v]-hash[f]+MOD)%MOD;
		int j;
		for(j=1;j<len/v;j++){
			ll bak=(hash[f+v*(j+1)]-hash[f+v*j]+MOD)%MOD;
			if(base*tx[v*j]%MOD!=bak)break;
		}
		if(j==len/v)return false;
	}
	return true;
}

int main(void){
	cin >> str;
	int n=str.size();
	tx[0]=1;
	for(int i=0;i<n;i++){
		hash[i+1]+=hash[i];
		hash[i+1]+=(str[i]-'a')*tx[i]%MOD;
		hash[i+1]%=MOD;
		tx[i+1]=tx[i]*26LL%MOD;
	}
	pat[0]=1;
	for(int i=0;i<=n;i++){
		dp[i]=n+5;
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(C(i,j)){
				if(dp[j]>dp[i]+1){
					pat[j]=0;
				}
				dp[j]=min(dp[j],dp[i]+1);
				if(dp[j]==(dp[i]+1)){
					pat[j]+=pat[i];
					pat[j]%=MOD;
				}
			}
		}
	}
	printf("%d\n",dp[n]);
	printf("%lld\n",pat[n]);
	return 0;
}

Compiler output:
a.cc: In function 'bool C(int, int)':
a.cc:24:26: error: reference to 'hash' is ambiguous
   24 |                 ll base=(hash[f+v]-hash[f]+MOD)%MOD;
      |                          ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc:24:36: error: reference to 'hash' is ambiguous
   24 |                 ll base=(hash[f+v]-hash[f]+MOD)%MOD;
      |                                    ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc:27:33: error: reference to 'hash' is ambiguous
   27 |                         ll bak=(hash[f+v*(j+1)]-hash[f+v*j]+MOD)%MOD;
      |                                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc:27:49: error: reference to 'hash' is ambiguous
   27 |                         ll bak=(hash[f+v*(j+1)]-hash[f+v*j]+MOD)%MOD;
      |                                                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc: In function 'int main()':
a.cc:40:17: error: reference to 'hash' is ambiguous
   40 |                 hash[i+1]+=hash[i];
      |                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc:40:28: error: reference to 'hash' is ambiguous
   40 |                 hash[i+1]+=hash[i];
      |                            ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc:41:17: error: reference to 'hash' is ambiguous
   41 |                 hash[i+1]+=(str[i]-'a')*tx[i]%MOD;
      |                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~
a.cc:42:17: error: reference to 'hash' is ambiguous
   42 |                 hash[i+1]%=MOD;
      |                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:11:4: note:                 'll hash [4001]'
   11 | ll hash[4001];
      |    ^~~~