F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

SNIBB

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1733    Accepted Submission(s): 509


Problem Description
  As we know, some numbers have interesting property. For example, any even number has the property that could be divided by 2. However, this is too simple.
  One day our small HH finds some more interesting property of some numbers. He names it the ¡°Special Numbers In Base B¡± (SNIBB). Small HH is very good at math, so he considers the numbers in Base B. In Base B, we could express any decimal numbers. Let¡¯s define an expression which describe a number¡¯s ¡°SNIBB value¡±.(Note that all the ¡°SNIBB value¡± is in Base 10)
  

    Here N is a non-negative integer; B is the value of Base.
  For example, the ¡°SNIBB value¡± of ¡°1023¡± in Base ¡°2¡± is exactly:10
(As we know (1111111111)2=(1023)(10))
  Now it is not so difficult to calculate the ¡°SNIBB value¡± of the given N and B.
But small HH thinks that must be tedious if we just calculate it. So small HH give us some challenge. He would like to tell you B, the ¡°SNIBB value¡± of N , and he wants you to do two kinds of operation:
1.  What is the number of numbers (whose ¡°SNIBB value¡± is exactly M) in the range [A,B];
2.  What it the k-th number whose ¡°SNIBB value¡± is exactly M in the range [A,B]; (note that the first one is 1-th but not 0-th)

Here M is given.
 

Input
  There are no more than 30 cases.
  For each case, there is one integer Q,which indicates the mode of operation;
  If Q=1 then follows four integers X,Y,B,M, indicating the number is between X and Y, the value of base and the ¡°SNIBB value¡±.
(0<=X,Y<=2000000000,2<=B<=64,0<=M<=300)
  If Q=2 then follows five integers X,Y,B,M,K, the first four integer has the same meaning as above, K indicates small HH want to know the k-th number whose ¡°SNIBB value¡± is exactly M.
(1<=K<=1000000000)
 

Output
  Output contains two lines for each cases.
  The first line is the case number, the format is exactly ¡°Case x:¡±, here x stands for the case index (start from 1.).
  Then follows the answer.
  If Q=2 and there is no such number in the range, just output ¡°Could not find the Number!¡± (without quote!) in a single line.
 

Sample Input
1 0 10 10 3 2 0 10 10 1 2 1 0 10 2 1
 

Sample Output
Case 1: 1 Case 2: 10 Case 3: 4
 

Hint

In case 1, the number in the range [0,10] whose ¡°SNIBB value¡± is exactly 3 is 3(in Base 10);
In case 2, the numbers in the range [0,10] whose ¡°SNIBB value¡± is exactly 1 are 1 and 10; Of course the 2-th number is 10.
In case 3, the number in the range [0,10] whose ¡°SNIBB value¡± is exactly 1 is 1,10,100,1000(in Base 2);
 

Author
AekdyCoin
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-24 13:38:05, Gzip enabled