poj1426 find the multiple

题目是说给定一个数 找出由0.1组成的它的倍数   链接点我

就是从一开始搜 每次要么乘以10 要么乘以10加上1 判断能否被整除即可

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int flag;
void dfs(unsigned __int64 a,int b,int c)
{
    if(flag==1) return;
    if(a%b==0){
        flag=1;
        cout<<a<<endl;
        return ;
    }
    if(c==19) return;//事先测一下
    dfs(a*10,b,c+1);
    dfs(a*10+1,b,c+1);
}
int main()
{
    int n;
    while(cin>>n&&n)
    {
        flag=0;
        dfs(1,n,0);
    }
    return 0;
}

就是这么短 就是这么任性
全部评论

相关推荐

2025-11-28 16:13
门头沟学院 Java
程序员小白条:年底了,都差不多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务