FZU Problem 2102 Solve equation (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2102

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

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

题意:

给出 A 和 B 求满足 A = k * B + d,的最大的K;

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

代码如下:

#include <cstdio>
#include <cstring>
int main()
{
    int t;
    int cas = 0;
    int c;
    char a[47], b[47];
    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;
}
时间: 2024-10-14 05:15:13

FZU Problem 2102 Solve equation (数学啊 )的相关文章

FZOJ 2102 Solve equation

                                                                                                                                     Problem 2102 Solve equation Accept: 1097    Submit: 2608Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Desc

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

FZU Problem 2110 Star (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2110 Problem Description Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower's classmates ask

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 (判断凸四边形)

题目链接 题意 : 给你n个点,判断能形成多少个凸四边形. 思路 :如果形成凹四边形的话,说明一个点在另外三个点连成的三角形内部,这样,只要判断这个内部的点与另外三个点中每两个点相连组成的三个三角形的面积和要与另外三个点组成的三角形面积相同. 中途忘了加fabs还错了好几次 1 //FZU2148 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <cmath>

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个进行防守的士兵们,每个参加完防守

FZU Problem 2034 Password table (简单模拟题)

这种简单题做了好长时间,我是不是有点逗? 地址:http://acm.fzu.edu.cn/problem.php?pid=2034 不解释了,自己看吧,练手的好题 上个代码吧 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include <stdio.h> #include <string.h> #include <stdlib.h>