Problem Description
You are given two positive integers A and B in Base C. For the equation:
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.
For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:
(1) A=0*B+123
(2) A=1*B+23
As we want to maximize k, we finally get one solution: (1, 23)
The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.
Output
Sample Input
Sample Output
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
int fun(string str,int b)
{
int sum=0;
int m;
int len=str.length();
for(int i=0;i<len;i++)
{
if(str[i]>='a') m=str[i]-'a'+10;
else m=str[i]-'0';
sum+=m*pow((double)b,(double)len-i-1);//fzu真坑,这里没有double也会编译错误
}
return sum;
}
int main()
{
int t;
string a,b;
int c,k,d;
scanf("%d",&t);
while(t--)
{
cin>>a>>b>>c;
int ai=fun(a,c);
int bi=fun(b,c);
k=ai/bi;
d=ai-k*bi;
printf("(%d,%d)\n",k,d);
}
return 0;
}