Bailian2972 (POJ noi0113-34,poj noi0201-1973) to determine the system of progressive violence __bailian2972

Source: Internet
Author: User

question link : POJ noi0113-34 determine the system.

question link : POJ noi0201-1973 determine the system. determining the system


Describe

6*9 = 42 is wrong for decimal, but it is true for the 13 binary. That is, 6 (13) * 9 (13) = 42 (13), while 42 (13) = 4 * 131+ 2 * 130 = 54 (10). Your task is to write a program that reads three integers p, q, and R, and then determines that a binary B (2<=b<=16) makes p * q = r. If B has many choices, the output is the smallest one. For example: p = one, q = one, R = 121. Then there are 11 (3) * 11 (3) = 121 (3) because 11 (3) = 1 * 31+ 1 * 30 = 4 (10) and 121 (3) = 1 * 32+ 2 * 31+ 1 * 30 = 16 (10). For system 10, there are 11 (10) * 11 (10) = 121 (10). In this case, you should output 3. If no proper feed is available, the output is 0. Enter a line that contains three integers p, q, R, separated by a single space between adjacent two integers. All bits of P, Q and R are numbers, and 1 <= p, q, R <= 1,000,000. Output an integer: the smallest b that makes p * q = r. If no suitable B is available, the output is 0. Sample input

6 9 42
Sample output
13

question Link : Bailian2972 determine the system

question brief : (slightly)

Problem Analysis :

This is a simple conversion problem.

The data entered is composed of a number (0-9).

Because if there are two answers then output a small value, so it needs to be from small to large test system.

At the beginning, the data is read in 10, and then converted to the specified system.

Program Description :

A shared function, convert (), was written to convert the data. 


Preface :

It is a good practice to encapsulate shared functionality into functions.


Reference link : (slightly)


The C language program for AC is as follows:

/* Bailian2972 OK/

#include <stdio.h>

#define BASE10
#define START 2 #define END

int convert (int val, int base)
{
    int ans, weight, R;

    Ans = 0;
    Weight = 1;
    while (Val) {
        r = val% BASE10;
        Val/= BASE10;

        if (r >= Base)
            return-1;

        Ans + + weight * r;

        Weight *= base;

    return ans;
}

int main (void)
{
    int p, q, R, I;
    int P2, q2, R2;

    scanf ("%d%d%d", &p, &q, &r);

    For (I=start i<=end; i++) {
        P2 = convert (P, i);
        if (P2 < 0)
            continue;

        Q2 = CONVERT (q, i);
        if (Q2 < 0)
            continue;

        r2 = CONVERT (r, i);
        if (R2 < 0)
            continue;

        if (P2 * q2 = = r2) break
            ;

    printf ("%d\n", I <= end? i:0);

    return 0;
}





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.