Integer’s Power

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 3208
64-bit integer IO format: %I64d      Java class name: Main

 
LMY and YY are number theory lovers. They like to find and solve some interesting number theory problems together. One day, they become interested in some special numbers, which can be expressed as powers of smaller numbers.

For example, 9=3^2, 64=2^6, 1000=10^3 …

For a given positive integer y, if we can find a largest integer k and a smallest positive integer x, such that x^k=y, then the power of y is regarded as k.
It is very easy to find the power of an integer. For example:

The power of 9 is 2.
The power of 64 is 6.
The power of 1000 is 3.
The power of 99 is 1.
The power of 1 does not exist.

But YY wants to calculate the sum of the power of the integers from a to b. It seems not easy. Can you help him?

 

Input

The input consists of multiple test cases.
For each test case, there is one line containing two integers a and b. (2<=a<=b<=10^18)

End of input is indicated by a line containing two zeros.

 

Output

For each test case, output the sum of the power of the integers from a to b.

 

Sample Input

2 10
248832 248832
0 0

Sample Output

13
5

Source

 
解题:容斥原理
 
表示$a^b$的数 个数要减去$a^{ib},其中i>1的数个数,因为可以表示成a^{ib}也能表示a^b的形式,但是a^b不是最小表示$
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL cnt[];
LL solve(LL x,int i = ){
if(x <= ) return x;
memset(cnt,,sizeof cnt);
for(i = ; i < ; ++i){
unsigned long long tmp = pow((long double)x + 0.5,(long double)1.0/i);
//if(tmp <= 1) break;
cnt[i] = tmp - ;
}
for(; i < ; i++) {
unsigned long long d;
bool yc = false;
for(d = ; !yc; d++) {
unsigned long long mi = ;
for(int j = ; !yc && j < i; j++) {
mi *= d;
if(mi > x) {
yc = true;
}
}
if(yc) break;
}
cnt[i] = d - ;
}
cnt[] = x;
for(int j = i-; j > ; --j){
for(int k = ; k < j; ++k)
if(j%k == ) cnt[k] -= cnt[j];
}
LL ret = cnt[];
for(int j = ; j < i; ++j)
ret += j*cnt[j];
return ret;
}
int main() {
LL a,b;
while(scanf("%I64d%I64d",&a,&b),a||b)
printf("%I64d\n",solve(b) - solve(a - ));
return ;
}

HDU 3208 Integer’s Power的更多相关文章

  1. hdu 3208 Integer’s Power 筛法

    Integer’s Power Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. 【HDOJ】3208 Integer’s Power

    1. 题目描述定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值.所求为区间$[a, b]$的数代入$f$的累加和,即\[\sum_{x=a}^{b} ...

  3. Integer’s Power HDU - 3208(容斥原理)

    找出(l,r)内的所有的指数最大的次方和 因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉. 然后开n方的部分,先用pow()函数找到最接 ...

  4. HDU Integer's Power(容斥原理)

    题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后 ...

  5. hdu 1047 Integer Inquiry

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...

  6. hdu 6034 B - Balala Power! 贪心

    B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...

  7. HDU 4461:The Power of Xiangqi(水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4461 题意:每个棋子有一个权值,给出红方的棋子情况,黑方的棋子情况,问谁能赢. 思路:注意“ if a play ...

  8. hdu acm-1047 Integer Inquiry(大数相加)

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. HDU 4658 Integer Partition(整数拆分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:给出n.k.求n的拆分方案数.要求拆分中每个数不超过k. i64 f[N]; void i ...

随机推荐

  1. 51Nod 1301 集合异或和 —— 异或DP

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1301 参考博客:https://blog.csdn.net/qq_ ...

  2. windows 7系统下安装SQL Server 2005图文教程

    由于工作需要,今天要在电脑上安装SQL Server 2005.以往的项目都是使用Oracle,MS的数据库还真的没怎么用过,安装Oracle已经轻车熟路,但装SQL Server好像还有点小麻烦,所 ...

  3. PCB 脱离IIS的Web应用

    在用.net Web编程中,我们写好的Web应用首选会挂在IIS上面,因为它足稳定并且功能齐全,但这不是我们唯一的选择,微软给我们提供了Owin组件,Web应该的宿主可以不再是IIS了,有了Owin后 ...

  4. Android内存管理(12)*「实例」用Monitor 生成.hprof文件 并分析内存泄漏

    参考 http://blog.csdn.net/xiaanming/article/details/42396507 基本步骤: 1,准备一个有内存泄漏的代码 2,如何发现内存泄漏 3,生成.hpro ...

  5. cocos2d-js 开发常见问题

    1. 编译android版本可能出现的问题记录 如果编译的时候报错.出现/platforms/android-14/arch-arm/usr/lib/crtend_so.o: Unknown EABI ...

  6. 网上流行的学生选课相关的50个常用sql语句

    学生表 Student(S#,Sname,Sage,Ssex) 教师表 Teacher(T#,Tname) 课程表 Course(C#,Cname,T#) 学生成绩表 SC(S#,C#,score) ...

  7. struts2.1.6存在中文乱码的bug

    如题,后续版本中已解决:可以通过添加filter的方式解决.

  8. zblog实现后台导航栏增加链接功能的最简单方法

    首先在ftp中找到这个目录   zb_system/admin/ 然后找到    admin_top.php      这个文件 再然后找到这行代码      <?php ResponseAdm ...

  9. 影响ERP成功实施的因素及实施方法

    一.影响ERP实施的因素 1.企业自身管理和认识上的问题.在ERP实施过程中没有用变革管理的理念和方法来策划和管理ERP的实施是导致ERP失败的主要原因. ERP作为一种管理工具他的实施本身就是操作手 ...

  10. CSS——盒子居中显示

    嵌套中个的子盒子使用了绝对定位,父盒子使用了相对定位.那么子盒子如何居中显示: 1.距离左偏离50% 2.margin-right子盒子宽度的一半 <!DOCTYPE html> < ...