Language: C++

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
 
inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}
 
inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 5e5 + 15;
const int K = 26;
int n;
pii ans(inf, 0);
string s;

int lp[N];

int p[K][N];

int pr[N], szp;

inline pii merge(pii a, pii b) {
	if(a.f == b.f)
		return mp(a.f, a.se + b.se);
	return min(a, b);
}

inline bool correct(string s) {
	for(int i = 1; i < s.size(); ++i) {
		if(s.size() % i == 0) {
			string t = s.substr(0, i);
			string nw = t;
			while(t.size() < s.size())
				t += nw;
			if(t == s)
				return false;
		}
	}
	return true;
}

inline bool correct(int l, int r) {
	return correct(s.substr(l, r - l + 1));
}

void rec(int i, int num, int last) {
	if(i == n) {
		if(last == n || correct(last, n - 1))
			ans = merge(ans, mp(num + (last != n), 1));
	}
	else {
		if(correct(last, i) && i != n - 1)
			rec(i + 1, num + 1, i + 1);
		rec(i + 1, num, last);
	}
}

inline int get(int c, int l, int r) {
	return p[c][r] - (l == 0 ? 0 : p[c][l-1]);
}

main() {
	lp[1] = 1;
	for(int i = 2; i < N; ++i) {
		if(!lp[i]) {
			lp[i] = i;
			pr[szp++] = i;
		}
		for(int j = 0; j < szp && pr[j] * i < N; ++j)
			lp[i * pr[j]] = pr[j];
	}
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
//    setin("input.txt");
    cin >> s;
    n = s.size();
    for(int i = 0; i < n; ++i) {
		for(int j = 0; j < K && i; ++j)
			p[j][i] = p[j][i-1];
		p[s[i] - 'a'][i]++;
	}
	ans = merge(n, 1);
    if(n <= 4)
		rec(0, 0, 0);
    else if(correct(s))
    	ans = mp(1, 1);
    else {
		for(int i = 1; i < n; ++i)
			if(lp[i] == i && lp[n - i] == n - i && get(s[0] - 'a', 0, i - 1) != i && get(s[i] - 'a', i, n - 1) != n - i)
				ans = merge(ans, mp(2, 1));
	}
	cout << ans.f << endl << ans.se << endl;
    return 0;
}

Compiler output:
a.cc:115:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  115 | main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:134:20: error: no matching function for call to 'merge(int&, int)'
  134 |         ans = merge(n, 1);
      |               ~~~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:11:
/usr/include/c++/14/bits/stl_algo.h:4857:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)'
 4857 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4857:5: note:   candidate expects 5 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:4908:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)'
 4908 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4908:5: note:   candidate expects 6 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator, _Compare)'
  412 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note:   candidate expects 7 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator)'
  417 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note:   candidate expects 6 arguments, 2 provided
a.cc:75:12: note: candidate: 'std::pair<int, int> merge(std::pair<int, int>, std::pair<int, int>)'
   75 | inline pii merge(pii a, pii b) {
      |            ^~~~~
a.cc:75:22: note:   no known conversion for argument 1 from 'int' to 'std::pair<int, int>'
   75 | inline pii merge(pii a, pii b) {
      |                      ^