<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abab&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> It is the substring &quot;ab&quot; twice.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aba&quot;
<strong>Output:</strong> false
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abcabcabcabc&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> It is the substring &quot;abc&quot; four times or the substring &quot;abcabc&quot; twice.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

from collections import Counter

def is_prime(n: int) -> bool:
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

class Solution:
    def repeatedSubstringPattern(self, s: str) -> bool:
        c = Counter(s)
        n = len(s)
        for i in range(2, n+1):
            if n % i != 0 or not is_prime(i):
                continue
            if any(v % i != 0 for v in c.values()):
                continue
            if s == s[:n // i] * i:
                return True
        return False
16800