Repeated String

0

0 votes
Easy
Problem

Riya has a string, s, of lowercase English letters that she repeated infinitely many times.

Given an integer, n, find and print the number of letter a's in the first n letters of Riya's 
infinite string.

For example, if the string s='abcac' and n=10, the substring we consider is 'abcacabcac', the 
first 10 characters of her infinite string. There are 4 occurrences of 'a' in the substring.

Input Format:

The first line contains a single string, s. 
The second line contains an integer, n.

Constraints
1. 1<=|s|<=100
2. 1<=n<=10^12

Output Format

Print a single integer denoting the number of letter a's in the first n letters of the infinite 
string created by repeating s infinitely many times.

Sample input:
abcac
10

Sample output:
4

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Editor Image

?