Integer’s Power HDU
来源:互联网 发布:淘宝客a5淘客交流 编辑:程序博客网 时间:2024/06/03 17:12
题意:给你l,r,问你在这个区间中the sum of the power of the integers
一个数能被另外一个数的a次方表示的,power of the integers 是最大的a
2<=l<=r<=10^18
这个并不是一般的那种容斥原理。
因为这个指数我们知道是在61之内的,然后我们可以枚举指数,然后dp[i]中存指数为i的数的个数,我们求个数的时候,,那个防溢出的真的是…….
去重是从后往前减。因为我们要求对应i的dp[i],而不是总数。
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>#include <queue>using namespace std;#define LL long longconst int maxn = 100;#define inf 1e18LL dp[maxn];LL a(LL x,int n){ LL ans=1,q=x; while(n) { if(n&1) { double tmp=1.0*inf/ans; if(q>tmp) return -1; ans=ans*q; } n>>=1; q=q*q; } return ans;}LL aa(LL n,LL i){ LL k=(LL)pow(n,1.0/i); LL l=a(k-1,i),r=a(k+1,i),mid=a(k,i); LL ans=0; if(r<=n&&r>0) ans=k+1; else if(mid<=n&&mid>0) ans=k; else if(l<=n&&l>0) ans=k-1; return ans;}LL solve(LL n){ memset(dp,0,sizeof(dp)); if(n==1) return 1; dp[1]=n; int i; for(i=2;i<62;i++) { dp[i]=aa(n,i)-1; if(dp[i]<=0) break; } for(int k=i-1;k>=1;k--) { for(int j=1;j<k;j++) { if(k%j==0) dp[j]-=dp[k]; } } LL ans=0; for(int h=1;h<i;h++) ans+=dp[h]*h; return ans;}int main(){ LL a,b; while(scanf("%I64d %I64d",&a,&b)!=EOF) { if(a==0&&b==0) break; LL a1=solve(b); LL a2=solve(a-1); printf("%I64d\n",a1-a2); } return 0;}
阅读全文
0 0
- Integer’s Power HDU
- HDU 3208 Integer’s Power 【容斥】
- hdoj Integer’s Power
- HDU 3208 - Integer's Power (容斥原理)
- HDU 3208 Integer’s Power 指数和、容斥
- hdu 3208 Integer’s Power (坑精度,容斥)
- hdu 3208 Integer’s Power(容斥原理)
- HDU 3208 Integer's Power(容斥原理、指数和、高精度求开根)
- 数学(hdu3208 - Integer’s Power)
- hdu3208 Integer's Power【容斥原理+精度处理】
- hdu 2603 && 比赛 D - Wiskey's Power
- HDU 2603 Wiskey's Power(物理题)
- power.s
- hdu——2603——Wiskey's Power
- hdu 2603 Wiskey's Power(数学题),待改正
- Wiskey's Power+数学题
- Integer.parseInt(s, radix)
- 浅谈Power"s"家族史--Power Povit vs. Power Query vs. Power View vs. Power BI
- 2017.7.8 C组总结
- MySQL中高级知识-MySQL架构介绍
- 【Eternallyc】C++中的sort排序函数
- Unable to instantiate application com.yunque.www.yunque.app.YunQuApplication: java.lang.ClassNotFoun
- 前端代码规范
- Integer’s Power HDU
- 一个完整的android项目需要哪些标配
- JAVA第一课第二节知识点
- Android PathEffect 效果使用
- ZJU1037-Gridland
- Spark参数配置
- map集合
- MapReduce读写hbase
- Java设计模式——责任链模式