این مسابقه در تاریخ پنج شنبه ۱۴ دی به صورت حضوری در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار شد.

A- Shayan's number


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Shayan, a computer engineering student at the University of Tehran with a great passion for mathematics, is a little bit lazy and always makes the minimum effort to solve every task he comes up with. In the first few weeks of school, Shayan’s little cousin Hadi has a few problems with his math exercises and asks Shayan to help him. These math exercises are all about the sum of digits of a number.

Shayan obviously teaches his little cousin how to solve them, but he also assigns Hadi some exercises to make sure that he really understands the concept. Due to his laziness, Shayan doesn’t want to think of some numbers to use. To save time, he will use a recursive strategy to create nn exercises of increasing difficulty that Hadi will use to practice.

The nn exercises are defined by Shayan as follows: First, we define an initial exercise made out of a single digit s1=ds_1 = d. Then, we define the remaining exercises with the following formula:

sn=sn1nsn1s_n = s_{n-1} * n * s_{n-1}

Where * is the operation of concatenation, for example 123456=12345612 * 34 * 56 = 123456. Now that the exercises are ready, help Shayan verify Hadi’s solutions by writing an algorithm that, given the initial digit dd and the index nn of the exercise, calculates the correct answer, i.e. the sum of the digits of sns_n.

input🔗

The first line contains two integers: dd and nn, respectively, the initial digit defined by Shayan and the index of the element of the sequence for which Shayan wants to calculate the sum of the digits.

0d90 \leq d \leq 9 1n601 \leq n \leq 60

output🔗

You need to write a single line containing the sum of digits of sns_n.

It is guaranteed that the result will fit in a normal signed 64-bit integer variable. It will definitely overflow a 32-bit variable.

example🔗

sample input 1🔗

1 3
Plain text

sample output 1🔗

11
Plain text

sample input 2🔗

3 11
Plain text

sample output 2🔗

6104
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.