forked from chencorey/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnexpected Problem.cpp
More file actions
48 lines (45 loc) · 994 Bytes
/
Unexpected Problem.cpp
File metadata and controls
48 lines (45 loc) · 994 Bytes
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
// https://www.hackerrank.com/contests/w23/challenges/commuting-strings
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
string input;
int m;
cin>>input>>m;
int k = 1;
int patternLength = input.length();
int temp = input.length();
while(k<=temp)
{
if(input.length()%k!=0)
{
k++;
continue;
}
string target = input.substr(0, k);
int i = 1;
bool valid = true;
while(k*i<input.length()&& valid)
{
valid = target == input.substr(k*i, k);
i++;
}
if(!valid)
{
k++;
continue;
}
else
{
patternLength = k;
break;
}
}
cout<<(m/patternLength)%1000000007;
return 0;
}