Alex Magic Product
Practice
3.5 (2 votes)
Modular arithmetic
Simple Math
Easy
Problem
64% Success 706 Attempts 20 Points 0.5s Time Limit 256MB Memory 1024 KB Max Code

Alex, a sophomore got inspired to do mathematics after watching a movie "The Man who knew Infinity". One day, he was studying mathematics in the library and in one of the books he discovered a way to perform multiplication of numbers in a new fashion by using digits of a number. He found that method interesting and decided to formulate an algorithm for the same method. Alex finds it difficult to implement and he asks for your help.

Given a number N. Let the first digit of the number be X. P1 is the number formed using first X digits of the given number in the sequence. Let the digit after Xth digit is Y. P2 is another number formed using Y digits starting from (X + 1)th position in sequence and so on. If the number of digits to be used to form a number are more than the remaining digits, then simply form the number using digits till the last digit. Product of (P1 * P2 * P3 ... * Pi) is known as magic product. Help Alex to find the magic product.

Input Format:
The first line of the input contains an integer T denoting the number of test cases. Each test case contains a number N followed by values of A and B respectively.

Output Format:
For each test case, output the magic product modulo 10A + B.

Constraints:

  • T ∈ [1, 105]
  • N ∈ [1, 10100]
  • A ∈ [1, 9]
  • B ∈ [0, 100]

NOTE: Any digit in the given number N will not be equal to 0.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
Basics of bit manipulationModular arithmetic
Points:20
1 votes
Tags:
Easy
Points:20
3 votes
Tags:
Easy