You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int INF = 0x3f3f3f3f ;
string s ;
int n ;
/**
测试用例:
abbaabbaabba
参考答案: 4
*/
//找出n的所有约数
const int N = 1010 ;
int a [ N ] ; //哪些约数
int cnt ; //共多少个
void find_divisors ( int n ) {
for ( int i = 1 ; i < = n / i ; i + + )
if ( n % i = = 0 ) {
a [ + + cnt ] = i ;
//防止出现5*5这样的录入两次
if ( i ! = n / i ) a [ + + cnt ] = n / i ;
}
}
int main ( ) {
cin > > s ;
n = s . size ( ) ;
//找约数
find_divisors ( n ) ;
//排序
sort ( a + 1 , a + 1 + cnt ) ;
//遍历约数尝试
for ( int i = 1 ; i < = cnt ; i + + ) {
string base = s . substr ( 0 , a [ i ] ) ;
bool flag = true ;
for ( int j = a [ i ] ; j < s . size ( ) ; j + = a [ i ] ) {
if ( s . substr ( j , a [ i ] ) ! = base ) {
flag = false ;
break ;
}
}
if ( flag ) {
cout < < a [ i ] < < endl ;
exit ( 0 ) ;
}
}
return 0 ;
}