zoukankan      html  css  js  c++  java
  • POJ

    题目链接

    http://poj.org/problem?id=1426

    题意
    给出一个数 要求找出 只有 0 和 1 组成的 十进制数字 能够整除 n
    n 不超过 200 十进制数字位数 不超过100

    思路
    其实 十进制数字位数 不超过 20 下就有可以满足的答案 所以直接用 unsinged long long 就可以过了
    。。

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = acos(-1.0);
    const double E = exp(1.0);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 5e4 + 5;
    const int MOD = 1e9 + 7;
    
    int n;
    
    ull ans;
    
    void dfs(ull x, int cur)
    {
        if (ans)
            return;
        if (cur > 19)
            return;
        if (x % n)
        {
            dfs(x * 10, cur + 1);
            dfs(x * 10 + 1, cur + 1);
        }
        else
        {
            ans = x;
            return;
        }
    }
    
    int main()
    {
        while (scanf("%d", &n) && n)
        {
            ans = 0;
            dfs(1, 0);
            cout << ans << endl;
        }
    }
    
    
    
    
  • 相关阅读:
    大二暑期周总结(四)
    大二暑期周总结(三)
    寒假十七
    寒假十六
    寒假十五
    寒假十四
    寒假十三
    寒假十二
    寒假十一
    寒假十
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433121.html
Copyright © 2011-2022 走看看