poj1426

来源:互联网 发布:unity3d 播放视频 编辑:程序博客网 时间:2024/05/18 03:31
一开始用bfs做,但发现用dfs做更快,短小精悍!
#include<cstdio>#define ll long longint k;bool dfs(int cnt,ll sum){    if(cnt>18)return false;    if(sum%k==0){        printf("%lld\n",sum);        return true;    }    if(dfs(cnt+1,sum*10))return true;    if(dfs(cnt+1,sum*10+1))return true;    return false;}int main(){    while(~scanf("%d",&k)&&k!=0){        dfs(0,1);    }    return 0;}

0 0