zoukankan      html  css  js  c++  java
  • 【GOJ 3010】有趣的数

    题目

    正解

    我们可以首先考虑在(k)进制下末尾有奇数个(0)的数(m)满足什么性质。

    当然,这部分可以通过打表找规律来实现。

    我们可以很显然的发现(m=a imes k^p(pequiv1pmod{m},a otequiv0pmod{k}))

    这样一来,我们可以很方便的统计出([1,n])范围内有多少个满足条件的数。

    对于需要查找的第(k)大,可以二分上边界得到。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    using LL=long long;
    LL n,k,c[105];
    LL sum(LL x) {
    	LL tot=0;
    	for(LL i=x; i>0; i-=2) {
    		tot+=(k-1)*pow(k,i-2);
    	}
    	if(x&1) {
    		tot++;
    	}
    	return tot;
    }
    bool check(LL x) {
    	LL cnt=0,tot=0;
    	while(x) {
    		c[++cnt]=x%k,x/=k;
    	}
    	for(LL i=1; i<=cnt; i++) {
    		tot+=c[i]*sum(i-1);
    	}
    	return tot>=n;
    }
    int main() {
    	scanf("%lld %lld",&n,&k);
    	LL l=1,r=1e18;
    	while(l<=r) {
    		LL mid=(l+r)>>1;
    		if(check(mid)) {
    			r=mid-1;
    		} else {
    			l=mid+1;
    		}
    	}
    	printf("%lld",l);
    	return 0;
    }
    
  • 相关阅读:
    JQuery使用总结
    JS应用总结
    Base64数据转成Excel,并处理Excel的格式
    HTTP压缩
    谷歌开发工具解析
    .Net LIst排重
    MySql日志系统
    .Net生成PDF流
    Mysql MVCC
    JAVA期末综合课程设计
  • 原文地址:https://www.cnblogs.com/Sam2007/p/13392221.html
Copyright © 2011-2022 走看看