ZOJ 2679 old Bill (math)

Source: Internet
Author: User

Topic Links:

problemcode=2679 "target=" _blank ">http://acm.zju.edu.cn/onlinejudge/showproblem.do?problemcode=2679


Among grandfather?? S papers a bill was found:

Turkeys $_679_

The first and the last digits of the number, the obviously represented the total price of those turkeys is replaced here By blanks (denoted _), for they is faded and is now illegible. What is the faded digits and what is the price of the one turkey?

We want to write a program, solves a general version of the above problem:

N Turkeys $_xyz_

The total number of turkeys, N, is between 1 and, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume that the first digit are nonzero, that's the price of one turkey are an integer number of dollars, and that all the Turkeys cost the same price.

Given N, X, Y, and Z, write a program that guesses the both faded digits and the original price. In case that there was more than one candidate for the original price, the output should was the most expensive one. That was, the program was to report the faded digits and the maximum price per turkey for the turkeys.

Input

The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. The first line of all test case contains an integer n (0 < n <), which represents the number of turkeys. In the following line, there is the three decimal digits X, Y, and Z, separated by a space, of the original price $_xyz_ .

Output

For each test case, the your program have to do the following. For a-test case, the there-than one candidate for the original price or there is none. In the latter case your program was to report 0. Otherwise, if there is more than one candidate for the original price, the program was to report the both faded digits and t He maximum price per turkey for the turkeys. The following shows sample input and output for three test cases.

Sample Input

3726 7 952 3 7780 0 5

Sample Output

3 2 5119) 5 184750
Source:Asia 2003, Seoul (South Korea)


Test instructions

Give an N and a three-digit number!

Want you to add a number to the first and last of this three-digit number! Make up five digits! This five-digit number can be divisible by n, and the maximum!

Ps:

Directly for Layer Two, enumerate the numbers on the first and the tail to be able! Can't be 0!


The code is as follows:

#include <cstdio>int main () {    int t;    int n;    int A, B, C;    int flag;    scanf ("%d", &t);    while (t--)    {        flag = 0;        scanf ("%d", &n);        scanf ("%d%d%d", &a,&b,&c);        for (int i = 9, i > 0; i--)        {for            (int j = 9; J >= 0; j--)            {                int tt = I*10000+A*1000+B*100+C*10+J;                if (tt%n = = 0)                {                    flag = 1;                    printf ("%d%d%d\n", i,j,tt/n);                    break;                }            }            if (flag)            {break                ;            }        }        if (!flag)            printf ("0\n");    }    return 0;}



Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

ZOJ 2679 old Bill (math)

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.