zoukankan      html  css  js  c++  java
  • HDU 4937 Lucky Number 规律题_(:зゝ∠)_

    把全部合法的进制打出来会发现合法的进制都是在 

    n/3 n/4 n/5的边上

    然后暴力边上的进制数。。


    #include <cstdio>
    #include <set>
    typedef long long ll;
    
    bool ok(ll x, ll y) {
        ll v;
        while (x > 0) {
            v = x % y;
            if (v != 3 && v != 4 && v != 5 && v != 6) 
                return false;
            x /= y;
        }    
        return true;
    }
    
    std::set<ll> vis;
    int T = 0;
    ll n;
    
    void work() {
        scanf("%I64d", &n);
        printf("Case #%d: ", ++T);
        if (n == 3 || n == 4 || n == 5 || n == 6)
            puts("-1");
        else {
            vis.clear();
            int ans = 0;
            ll base;
            for (int i = 1; i <= 50 && i < n; ++i) {
                for (int j = 0; j <= 50; ++j) {
                    base = n / i + j;
                    if (base <= 1 || base >= n || vis.count(base) > 0)
                        continue;
                    vis.insert(base);
                    if (ok(n, base))
                        ++ ans;
                }
                for (int j = 1; j <= 50; ++j) {
                    base = n / i - j;
                    if (base <= 1 || base >= n || vis.count(base) > 0)
                        continue;
                    vis.insert(base);
                    if (ok(n, base))
                        ++ ans;
                }
            }
            for (int i = 2; i < n && i <= 1000; ++i) {
                if (vis.count(i))
                    continue;
                vis.insert(i);
                if (ok(n, i))
                    ++ ans;
            }
            printf("%d
    ", ans);
        }
    }
    
    int main() {
        int cas;
        scanf("%d", &cas);
        while (cas -- > 0) 
            work();
        return 0;
    }


  • 相关阅读:

    php多版本环境变量设置
    vagrantbox 磁盘扩容
    # Csv数据导入导出
    php把数组写入文件
    log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
    springmvc 多个拦截器执行的顺序
    yum 源修改
    连接(JOIN)运算
    SQL基本概述
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4082717.html
Copyright © 2011-2022 走看看