现在的位置: 首页 > 综合 > 正文

Magic Multiple

2014年04月05日 ⁄ 综合 ⁄ 共 1321字 ⁄ 字号 评论关闭

点击打开链接

 

 

Problem F: Magic Multiple

Time Limit: 1 Sec  Memory Limit:
128 MB
Submit: 36  Solved: 23
[Submit][Status][Web Board]

Description

The Elvish races of Middle Earth believed that certain numbers were more significant than
others. When using a particular quantity n of metal to forge a particular sword, they believed that
sword would be most powerful if the thickness k were chosen according to the following rule:
Given a nonnegative integer n, what is the smallest k such that the decimal representations of
the integers in the sequence:
n,2n,3n,4n,5n,...,kn
contain all ten digits (0 through 9) at least once?
Lord Elrond of Rivendell has commissioned you with the task to develop an algorithm to find
the optimal thickness (k) for any given quantity of metal (n).

Input

Input will consist of a single integer n per line. The end of input will be signaled by end of file.
The input integer will be between 1 and 200,000,000, inclusive.

Output

The output will consist of a single integer per line, indicating the value of k needed such that every
digit from 0 through 9 is seen at least once.

Sample Input

1
10
123456789
3141592

Sample Output

10
9
3
5

 

题意:输入n,让你求最小的k。要求是1*n,2*n.......k*n包含0到 9所有的数字。

#include<stdio.h>
#include<string.h>
int s[10];
int main()
{
    int i,j;
    long long n;
    while(scanf("%lld",&n)!=EOF)
    {
       long long  flag;
       int flag1,x;
        memset(s,0,sizeof(s));
        for(i=1;;i++)
        {
            flag=n*i;
            flag1=0;
            while(flag)
            {
                x=flag%10;
                s[x]=1;
                flag/=10;
            }
            for(j=0; j<=9; j++)
            {
                if(s[j]==0)
                {
                    flag1=1;
                    break;
                }
            }
            if(!flag1)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

 

 

 

 

抱歉!评论已关闭.