福建2012年省赛C

来源:互联网 发布:数据挖掘待遇 编辑:程序博客网 时间:2024/04/24 13:23



Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice FZU 2102

Description

You are given two positive integers A and B in Base C. For the equation:

A=k*B+d

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

For each test case, output the solution “(k,d)” to the equation in Base 10.

Sample Input

3
2bc 33f 16
123 100 10
1 1 2

Sample Output

(0,700)
(1,23)
(1,0)

#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>using namespace std;char a[110];char b[110];__int64  jzzh(char *s,__int64  n){__int64 ans=0,l=strlen(s),d=1;for(int i=l-1;i>=0;--i){if(s[i]>='0'&&s[i]<='9'){ans+=(s[i]-'0')*d;}else {ans+=(s[i]-'a'+10)*d;}d*=n;}return ans;}int main(){__int64 A,B,C,i,j,k,t;scanf("%I64d",&t);while(t--){scanf("%s %s %I64d",a,b,&C);A=jzzh(a,C);B=jzzh(b,C);if(A<B){printf("(%I64d,%I64d)\n",0,A);continue;}__int64 ans=0,m=0;while(A>=ans*B){ans++;}ans--; printf("(%I64d,%I64d)\n",ans,A%(ans*B));}return 0;}


Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice FZU 2102

Description

You are given two positive integers A and B in Base C. For the equation:

A=k*B+d

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

For each test case, output the solution “(k,d)” to the equation in Base 10.

Sample Input

32bc 33f 16123 100 101 1 2

Sample Output

(0,700)(1,23)(1,0)

0 0
原创粉丝点击