Crack the Code
Over the past year you've been taking a hacking course and now it's time to show what you've learned in a test! The test has 1 problem that is simple (or at least that's what your teacher, Mr. Ergastopoulos, says): you have to break a code to get the PIN for a credit card.
Thankfully, you've been taught this way of coding during your course: You can store a number within another with a parameter: the so-called "base" . To recover , knowing you perform the following calculation:
- c++ / java etc.:
x = A % b;
- python:
x = A % b
is thus the remainder of the integer division .
But what happens when you want to store various numbers within using ? Mr. Ergastopoulos hasn't taught you how (you do need to do some things by yourself in the exam!), but has told you that you can "clean" from in order to read :
- c++ / java κ.λπ.:
x = A / b;
- python:
x = A // b
So you divide by and keep the whole part of the division. Now you can get , as you learned above.
An example for:
- To get the first hidden number, you do:
- To "clear" the first hidden number, you do:
- To get the second hidden number, you do:
- and so forth.
Problem
Write a script that reads the base and the number and finds the requested hidden PIN digits.
Examples
1st
STDIN
10 42172413
5
1 2 8 4 2
STDOUT
3
1
4
2
1
Explanation
We break into :
The requested digits are therefore:
(we don't care that is being requested twice, the answer stays the same)
2nd
STDIN
4 343434
3
1 3 5
STDOUT
2
0
1
Restrictions
- always expresses a number that is stored in (eg. the third hidden digit in number with base or the 0th digit of a number will not be requested).
For an extra 20% of the grade, (use
long long
instead of int
in languages such as C/C++/Java etc.)
Comments