UVA 725 Division (Division) Violence Law!

Source: Internet
Author: User

UVA 725 Division (Division)A-Brute Force solutionTime limit:3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu  

Description

Write a program, finds and displays all pairs of 5-digit numbers, between them use the digits 0 through 9 Once each, such the first number divided by the second are equal to an integer N, where. That's,


Abcde/fghij = N

Where each letter represents a different digit. The first digit of the numerals is allowed to be zero.

InputEach line of the input file consists of a valid integer N. An input of zero was to terminate the program.

OutputYour program has to display all qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator ).

Your output should is in the following general form:


xxxxx/xxxxx = N

xxxxx/xxxxx = N

.

.


In case there is no pairs of numerals satisfying the condition, you must write 'there is no solutions for N.". Separate the output for both different values of N by a blank line.

Sample Input
61620

Sample Output
There is no solutions for 61.79546/01283 = 6294736/01528 = 62

Test instructions
Enter positive integer n to output all expressions, such as abcde/fghij=n, in order from small to large, where a-j happens to be an arrangement of the number 0-9 (can have 0 preamble)  2=<n<=79
Ideas:

Can use five-layer loops, but the process is a bit cumbersome
You can also enumerate fghij only to calculate ABCDE, and then the judge does not meet the criteria.

#include <stdio.h>intp[ the];intJuge (intAintb//determine the eligible A, B, mark A, B, every bit{    if(A >98765)        return 0;  for(inti =0; I <Ten; i++) {P[i]=0; }    if(b<10000) p[0]=1;  while(a) {P[a%Ten] =1;//judge each bit, and then MarkA/=Ten; }     while(b) {p[b%Ten] =1; b/=Ten; }    intTotal =0;  for(inti =0; I <Ten; i++) Total+=P[i]; returntotal==Ten;//until there are 10 numbers that meet the criteria}intMain () {intN, m =0;  while(SCANF ("%d", &n) = =1, N) {        if(m>0) printf ("\ n"); m++;//Output Format Requirements        intf =1;  for(inti =1234; I <99999; i++)//The scope should be very good to come up        {            if(Juge (i*n,i)) {printf ("%d/%05d =%d\n", i*n,i,n);//format control output, five digits if missing, fill it with 0.f =0; }        }        if(f) {printf ("There is no solutions for%d.\n", N); }    }    return 0;}

UVA 725 Division (Division) Violence Law!

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.