division (enumeration)

Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0through 9 once each, such that the first number divided by the second is equal to an integer N, where2 ≤ N ≤ 79. That is,abcdefghij = N where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.

 Input Each line of the input file consists of a valid integer N. An input of zero is to terminate the program.OutputYour program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and,of course, denominator).Your output should be in the following general form:xxxxx / xxxxx = N xxxxx / xxxxx = N..In case there are no pairs of numerals satisfying the condition, you must write ‘There are no solutions for N.’. Separate the output for two different values of N by a blank line.

Sample Input

61

62

0

Sample Output

There are no solutions for 61.


79546 / 01283 = 62

94736 / 01528 = 62


Source : https://vjudge.net/contest/227390#problem/A

 
 
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
intmain()
{
    int k,n=0;
    while(cin>>k)
    {
        if(k==0) break;
        if(n!=0) cout<<endl;
        n++;
        int c,i,j,flag=0;
        for(i=1234;i<98765;i++)
        {
            int a[15]={0};
            c=i*k;
            if(c>98765) break;
            a[i%10]++;a[i/10%10]++;a[i/100%10]++;a[i/1000%10]++;a[i/10000]++;
            a[c%10]++;a[c/10%10]++;a[c/100%10]++;a[c/1000%10]++;a[c/10000]++;
            for(j=0;j<10;j++)
            if(a[j]>1)
                break;
            if(j==10)
            {
                flag=1;
                printf("%05d / %05d = %d\n",c,i,k);
            }
        }
        if(flag==0) printf("There are no solutions for %d.\n",k);
    }
    return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325381785&siteId=291194637