Language: C++

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 500010
string s;
int n;
#define M 1
ll hash[M][N];
ll hmod[M] = {1e9+7};
ll base[M] = {101};
ll pow[M][N];

bool all_equal(){
	rep(i, n-1) if(s[i]!=s[i+1]) return false;
	return true;
}

void init_hash(){
	for(int t = 0; t < M; t++){
		hash[t][0] = 0;
		rep(i, n){
			hash[t][i+1] = ((hash[t][i]*base[t])+s[i])%hmod[t];
		}
		pow[t][0] = 1;
		rep(i, n) pow[t][i+1] = (pow[t][i]*base[t])%hmod[t];
	}
}

bool same(int x1, int x2, int k){
	for(int t = 0; t < M; t++){
		ll r1 = ((hash[t][x1+k]-hash[t][x1]+hmod[t])%hmod[t])*pow[t][n-x1]%hmod[t];
		ll r2 = ((hash[t][x2+k]-hash[t][x2]+hmod[t])%hmod[t])*pow[t][n-x2]%hmod[t];
		if(r1!=r2) return false;
	}
	return true;
}

int main(){
	cin>>s;
	n = s.size();
	if(all_equal()){
		cout<<n<<endl;
		cout<<1<<endl;
		return 0;
	}
	init_hash();
	for(int i = 2; i <= n/2; i++){
		int j = n/i;
		if(i*j!=n) continue;
		bool flag = true;
		for(int k = 1; k < j; k++){
			if(!same(0, i*k, i)){
				flag = false;
				break;
			}
		}
		if(flag){
			//cerr<<i<<" "<<j<<endl;
			cout<<2<<endl;
			ll res = (ll)(i-1)*j;
			if(j==2) res++;
			res %= mod;
			cout<<res<<endl;
			return 0;
		}
	}
	cout<<1<<endl;
	cout<<1<<endl;
	return 0;
}


Compiler output:
a.cc:45:18: error: narrowing conversion of '1.000000007e+9' from 'double' to 'll' {aka 'long long int'} [-Wnarrowing]
   45 | ll hmod[M] = {1e9+7};
      |               ~~~^~
a.cc:47:4: warning: built-in function 'pow' declared as non-function [-Wbuiltin-declaration-mismatch]
   47 | ll pow[M][N];
      |    ^~~
a.cc: In function 'void init_hash()':
a.cc:56:17: error: reference to 'hash' is ambiguous
   56 |                 hash[t][0] = 0;
      |                 ^~~~
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/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:6:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~
a.cc:58:25: error: reference to 'hash' is ambiguous
   58 |                         hash[t][i+1] = ((hash[t][i]*base[t])+s[i])%hmod[t];
      |                         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~
a.cc:58:42: error: reference to 'hash' is ambiguous
   58 |                         hash[t][i+1] = ((hash[t][i]*base[t])+s[i])%hmod[t];
      |                                          ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~
a.cc: In function 'bool same(int, int, int)':
a.cc:67:27: error: reference to 'hash' is ambiguous
   67 |                 ll r1 = ((hash[t][x1+k]-hash[t][x1]+hmod[t])%hmod[t])*pow[t][n-x1]%hmod[t];
      |                           ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~
a.cc:67:41: error: reference to 'hash' is ambiguous
   67 |                 ll r1 = ((hash[t][x1+k]-hash[t][x1]+hmod[t])%hmod[t])*pow[t][n-x1]%hmod[t];
      |                                         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~
a.cc:68:27: error: reference to 'hash' is ambiguous
   68 |                 ll r2 = ((hash[t][x2+k]-hash[t][x2]+hmod[t])%hmod[t])*pow[t][n-x2]%hmod[t];
      |                           ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~
a.cc:68:41: error: reference to 'hash' is ambiguous
   68 |                 ll r2 = ((hash[t][x2+k]-hash[t][x2]+hmod[t])%hmod[t])*pow[t][n-x2]%hmod[t];
      |                                         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:44:4: note:                 'll hash [1][500010]'
   44 | ll hash[M][N];
      |    ^~~~