Fzu problem 2102 Solve equation (math AH)

Source: Internet
Author: User

Title Link: http://acm.fzu.edu.cn/problem.php?pid=2102


Problem Description

You are given, 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 on this problem, we want to maximize K.

For example, a= "123" and b= "", c=10. So both A and B is 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 +, and we use ' a ', ' B ', ' C ', ' d ', ' e ', ' f ' to represent, one, one, ten,, and Respectiv Ely.

Input

The first line of the input contains an integer T (t≤10), indicating the number of the test cases.

Then T-cases, for any case, is 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume this in Base, both A and B are less than 2^31.

Outputfor each test case, output the solution "(k,d)" to the equation in Base 10. Sample INPUT32BC 33f 16123 101 1 2 Sample Output (0,700) (1,23) (1,0) Source "Higher Education Cup" the third Fujian University student Program Design Competition
Test Instructions:

Given A and b to satisfy a = k * B + D, the largest k;

C means a, and B is a binary!

The code is as follows:

#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;}


Fzu problem 2102 Solve equation (math AH)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.