1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include<bits/stdc++.h>
using namespace std;
template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;} template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}
typedef long long LL; typedef vector<int> vi; typedef pair<int, int> pii; #define mp(x, y) make_pair(x, y) #define pb(x) emplace_back(x)
const int N = 5000005; const int MOD[3] = {10000019, 5000011, 7000061};
int power[3][N], base = 233; int h[3][N]; inline int getSubstring(int l, int r, int _){ if(l > r) return 0; int res = (h[_][r] - 1ll * h[_][l-1] * power[_][r - l + 1] % MOD[_]) % MOD[_]; res %= MOD[_]; if(res < 0) res += MOD[_]; return res; }
int T, n; char s[N], t[N]; int b[10000100], id;
inline bool check(int _, int k){ id++; for(int i = 1; i <= k; i++){ int tmp = (1ll * getSubstring(i, k, _) * power[_][i-1] % MOD[_] + getSubstring(1, i-1, _)) % MOD[_]; tmp %= MOD[_]; if(tmp < 0) tmp += MOD[_]; b[tmp] = id; } for(int i = 1; i <= n; i += k) if(b[getSubstring(i, i + k - 1, _)] != id) return false; return true; }
void solve(){ read(n); scanf("%s", s+1); for(int _ = 0; _ <= 2; _++) for(int i = 1; i <= n; i++) h[_][i] = (1ll * h[_][i-1] * base % MOD[_] + s[i]) % MOD[_]; for(int i = 1; i < n; i++){ if(n % i) continue; bool tag = true; for(int _ = 0; _ <= 2; _++){ if(!check(_, i)){ tag = false; break; } } if(tag) return puts("Yes"), void(); } puts("No"); }
int main(){ for(int _ = 0; _ <= 2; _++){ power[_][0] = 1; for(int i = 1; i <= 5000000; i++) power[_][i] = (1ll * power[_][i-1] * base) % MOD[_]; } for(read(T); T; T--) solve(); return 0; }
|