Integer’s Power HDU - 3208 组合数学
2017-07-08 16:14
417 查看
题意:给你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],而不是总数。
一个数能被另外一个数的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 long const int maxn = 100; #define inf 1e18 LL 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; }
相关文章推荐
- 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 HDU - 3208 组合数学
- Integer’s Power HDU - 3208 组合数学
- Integer’s Power HDU - 3208 组合数学
- 【HDU 3208】 组合数学+动态规划 湫秋系列故事——安排座位
- hdu 3208 Integer’s Power 筛法
- HDU 3208 Integer’s Power 【容斥】
- HDU 4048 Zhuge Liang's Stone Sentinel Maze [组合数学+Burnside]
- HDU 1027 组合数学
- hdu 4790 数论 实现 组合数学
- hdu 4497 GCD and LCM(组合数学)
- hdu 2603 Wiskey's Power(数学题),待改正
- HDU -1261 组合数学。
- hdu2049(组合数学)
- hdu 4045 Machine scheduling(组合数学)
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 (组合数学)