'Any alternate way to execute the program faster
n,k,m=map(int,input().split())
s=input()
while m>0:
pre=len(s)
for i in s:
s+=str(int(i)*k)
s=s[pre:]
m-=1
print(len(s))
Aim is to determine the number of white balls after M levels. Note that K remains the same for every level.
n,m,k are integers and s is string called power of ball(0<=s>=9) , s is single digit
INPUT-4 9 2
5418
OUTPUT-14
Exlanation-Initially S=5418
After the 1st, level S=4536972
After the 2nd level, S=36452754816318
length of s is 14
Solution 1:[1]
n, k, m = map(int, input().split())
s = input()
for m in range(m, 0, -1):
pre = len(s)
for i in s:
s += str(int(i) * k)
s = s[pre:]
print(len(s))
Code above has O(m*s) time Complexity
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abdullah Omer |