“Base B”
AekdyCoin is so fond of math.He loves Number.He knows how to express a non-negative number into P base.Say,he knows that the number 71 in 2 Base is exactly “1000111”. But AekdyCoin doesn’t think it’s a proper way to express a number.AekdyCoin want to creat the “Base B”,whose digits’ value is not only equal or larger than A,but also smaller than A+B.For example,if A = 1,B = 5,then AekdyCoin could express number 65 in “Base 5” ,it is “225” definitely .(But Not “230”,0 is out of the range [1,5]!)
AekdyCoin is quite exciting about his “invention”,now he hopes that you could write a program for him which could help him to express a number in “Base B”.
Input
The input consists of several test cases.
Every case has only three integers indicating N,A,B (0<=N<=10^9,0<=A<=100,2<=B<=100)
Output
For each case,you should output “Case x:” first where x is the case index.(x>=1).
Then output the expression in “Base B”,if the number of digit is more than one,you should split them with exactly one ‘ ‘.
We guarantee there is always a solution.
Sample Input
65 1 5 15 0 2
Sample Output
Case 1: 2 2 5 Case 2: 1 1 1 1
Hint
Hint: In case 1, 65 = 2 * 5^2 + 2 * 5 + 5 * 1,and all digits are in the range[1,5].
题意:要求转化为b进制 而且每个位数上的数不能小于a
题解:先把数转化为b进制然后 如果当前位数小于a 从前一位借1 然后当前位加b
自己写一写就明白了
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
#define maxn 10010
int arr[maxn];
int main(){
int n,a,b,Case=0;
while(scanf("%d%d%d",&n,&a,&b)!=EOF){
int coun=0;
while(n){
arr[coun++]=n%b;
n/=b;
}
for(int i=0;i<coun-1;i++){
while(arr[i]<a){
arr[i]+=b;
arr[i+1]--;
}
}
printf("Case %d:",++Case);
for(int i=coun-1;i>=0;i--){
printf(" %d",arr[i]);
}printf("\n");
}
return 0;
}