Find The Multiple

Posted 中单支援路死河道

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Find The Multiple相关的知识,希望对你有一定的参考价值。

题意:给定一个n找十进制只包含0 1 并且为n的倍数的数,注意数据范围就可以了,dfs不难理解

代码如下:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
bool vis;
void dfs(ll x,int n,int k)
{
    if(vis)
        return ;
    if(x%n==0)
       {    vis=true;
           printf("%llu\n",x);//无符号longnlong输出用llu,我用lld答案错误了
           return ;
       }
       if(k==19)
        return ;
       dfs(x*10,n,k+1);
       dfs(x*10+1,n,k+1);


}
int main()
{
    int m;
    while(scanf("%d",&m),m!=0)
    {
        vis=false;
        dfs(1,m,0);
    }
}

 

以上是关于Find The Multiple的主要内容,如果未能解决你的问题,请参考以下文章

POJ 1426 Find The Multiple

ZOJ 1530 - Find The Multiple

Find The Multiple

Find The Multiple

POJ - 1426 Find The Multiple

poj 1426 Find The Multiple