「CFgym100541」ATM withdrawal

2015年3月14日2,6910

Vinh works for an ATM machine manufacturing company. The basic functionality of an ATM machine is cash withdrawal. When a user requests a cash withdrawal of W VND (Vietnamese Dong), the ATM has to dispense Nmoney notes such that they sum up to W. For the next generation of ATM machine, Vinh is working on an algorithm to minimize the number N of money notes for each cash withdrawal transaction.

Your task is to help Vinh to do his job given that the money notes come in the values of 1000, 2000, 3000, 5000, 1000 * 101, 2000 * 101, 3000 * 101, 5000 * 101, …, 1000 * 10c, 2000 * 10c, 3000 * 10c, 5000 * 10c where c is a positive integer and Vinh has unlimited supply of money notes for each value.

Input

The input file consists of several datasets. The first line of the input file contains the number of datasets which is a positive integer and is not greater than 1000. The following lines describe the datasets.

  • The first line consists of one positive integer W (W ≤ 1018);
  • The second line consists of one positive integer c (c ≤ 15).
Output

For each dataset, write in one line two space-separated integers N and S where S is the number of ways to dispense the fewest number N of money notes. In case there is no way to serve the cash withdrawal request, write out 0 in one line instead.

Sample test(s)
input

output

 

题解

显然低位不涉及进位的问题。。。

所以预处理组成1-9的最少个数和方案

低于c的按位统计,其余乱搞一下

 

avatar
  Subscribe  
提醒