Skip to content

Commit 32de080

Browse files
authored
Create 1733-FindingPeriods.cpp
we basically checked for all the periods time comp-O(nlogn) bcs (n/1 + n/2 + n/3 + n/4 + ........+ n/n)=logn;
1 parent 44b7bae commit 32de080

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// JAI BAJARANG BALI
2+
3+
// manitianajay45
4+
5+
// give me some sunshine, give me some rain , give me another chacne to grow up once again....
6+
7+
// sab moh maya hai....
8+
9+
#include<bits/stdc++.h>
10+
using namespace std;
11+
12+
#define ll long long
13+
14+
#define mod 1000000007
15+
16+
17+
int main(){
18+
string s;
19+
cin>>s;
20+
ll n=s.length();
21+
22+
ll x=0;
23+
ll y=0;
24+
vector<ll> zrr(n,0);
25+
s+='*';
26+
for(ll i=1;i<n;i++){
27+
zrr[i]=max(0ll,min(zrr[i-x],(y-i+1)));
28+
29+
while(i+zrr[i]<n && s[zrr[i]]==s[i+zrr[i]]){
30+
31+
x=i;
32+
y=i+zrr[i];
33+
zrr[i]++;
34+
}
35+
36+
}
37+
// for(ll i=0;i<n;i++){
38+
// cout<<zrr[i]<<" ";
39+
// }
40+
// cout<<endl;
41+
42+
for(ll i=1;i<=n-1;i++){
43+
ll j=i;
44+
bool flag=true;
45+
while(j<n){
46+
if(zrr[j]<i && (j+zrr[j])<n){
47+
flag=false;
48+
break;
49+
}
50+
j+=i;
51+
}
52+
if(flag){
53+
cout<<i<<" ";
54+
}
55+
}
56+
57+
cout<<n<<endl;
58+
59+
return 0;
60+
61+
}

0 commit comments

Comments
 (0)