zoukankan      html  css  js  c++  java
  • ZR#990

    ZR#990

    解法:

    首先,一个 $ k $ 进制的数的末尾 $ 0 $ 的个数可以这么判断

    while(x) {
        x /= k;
        cnt++;//cnt为0的个数
    }
    

    因为这道题的 $ 0 $ 的个数是奇数个,所以我们可以很快的知道 $ k_1,k_3,k_5 cdots $ 的值。
    又因为能被 $ k_i $ 整除的数一定能被 $ k $ 整除,所以我们可以简单容斥+二分解决问题。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    
    using namespace std;
    
    #define LL long long
    
    LL n,k,ans;
    
    inline LL check(LL x) {
        LL flag = 1,res = 0;
        while(x) {
            x /= k;
            res += flag * x;
            flag = -flag;
        }
        return res;
    }
    
    int main() {
        scanf("%lld%lld",&n,&k);
        LL l = 1,r = 1e18;
        while(l <= r) {
            LL mid = (l + r) >> 1;
            if(check(mid) < n) {
                l = mid + 1;
                ans = l;
            }
            else r = mid - 1;
        }
        printf("%lld
    ",ans);
        //system("pasue");
        return 0;
    }
    
  • 相关阅读:
    语言只是个工具
    最近学到的一点东西
    iBeacon开发
    马上着手开发Mac应用程序
    Text Kit入门
    Text Kit进阶
    Web Notification
    Objective-C异步编程
    Clang Language Extensions
    黑客与画家
  • 原文地址:https://www.cnblogs.com/Repulser/p/11581093.html
Copyright © 2011-2022 走看看