[kuangbin带你飞]专题一 简单搜索- E - Find The Multiple

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define INF 0x3f3f3f
int gcd(int a, int b) {return b==0 ? a:gcd(b,a%b);}

int n;
int flag;
unsigned long long ans;
void dfs(unsigned long long x, int step)
{
    if(flag||step>19) return;
    if(x%n==0){
        flag = 1;
        ans = x;
        return;
    }
    dfs(x*10,step+1);
    dfs(x*10+1,step+1);
}   

int main()
{
    while(~scanf("%d", &n))
    {
        if(n==0) break;
        flag = 0;
        dfs(1,1);
        printf("%llu\n", ans);
    }
    return 0;
}

你可能感兴趣的:(kuangbin)