-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathRepeatedString.java
More file actions
32 lines (30 loc) · 735 Bytes
/
Copy pathRepeatedString.java
File metadata and controls
32 lines (30 loc) · 735 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
long n = in.nextLong();
int l = s.length();
char c[]=s.toCharArray();
int no[]=new int[l];
no[0]=0;
if(c[0]=='a')
no[0]=1;
for(int i=1;i<l;i++){
no[i]=no[i-1];
if(c[i]=='a')
no[i]++;
}
long r=n/l;
int rem = (int)(n%l) - 1;
long sum=0;
sum+=r*no[l-1];
if(rem>=0)
sum+=no[rem];
System.out.println(sum);
}
}