# FZU Problem 2102 Solve equation （数学啊 ）

## Problem 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)

## Source

“高教社杯”第三届福建省大学生程序设计竞赛

c表示A, 和B是几进制！

```#include <cstdio>
#include <cstring>
int main()
{
int t;
int cas = 0;
int c;
char a, b;
scanf("%d",&t);
while(t--)
{
int t1 = 0, t2 = 0;
scanf("%s%s%d",a,b,&c);
int len1 = strlen(a);
int len2 = strlen(b);
for(int i = 0; i < len1; i++)
{
t1 *= c;
if(a[i]<='9' && a[i]>='0')
t1+=a[i]-'0';
else
t1+=a[i]-'a'+10;
}

for(int i = 0; i < len2; i++)
{
t2 *= c;
if(b[i]<='9' && b[i]>='0')
t2+=b[i]-'0';
else
t2+=b[i]-'a'+10;
}
printf("(%d,%d)\n",t1/t2,t1%t2);
}
return 0;
}
```

## ACM: FZU 2102 Solve equation - 手速题

FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Practice 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-negati

## FZU 2102 Solve equation 多进制计算

Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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

## FZU 2102 Solve equation（水，进制转化）&amp;&amp; FZU 2111（贪心，交换使数字最小）

C 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-negativ

## Solve Equation gcd(x,y)=gcd(x+y,lcm(x,y)) gcd(x,y)=1 =&gt; gcd(x*y,x+y)=1

/** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生选拔赛题 题意:给定两个数的和以及他们的最小公倍数,求这两个数. 思路: x+y=A lcm(x,y)=B => x*y/gcd(x,y)=B 要把这两个公式联立,那么必须消掉gcd: 设:d = gcd(x,y), x = kx*d, y = ky*d; kx与ky互质: x+y=A => d(

## FZU Problem 2148 Moon Game （判断凸四边形） ## FZU Problem 2171 防守阵地 II (线段树，区间更新) Problem 2171 防守阵地 II Accept: 143    Submit: 565Time Limit: 3000 mSec    Memory Limit : 32768 KB  Problem Description 部队中总共有N个士兵,每个士兵有各自的能力指数Xi,在一次演练中,指挥部确定了M个需要防守的地点,指挥部将选择M个士兵依次进入指定地点进行防守任务,获得的参考指数即为M个士兵的能力之和.随着时间的推移,指挥部将下达Q个指令来替换M个进行防守的士兵们,每个参加完防守