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. win32 API函数

    cozy的博文 win32 API函数大全   (2008-03-15 16:28) 分类: 个人日记 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WN ...

  2. 编码格式(UTF-8 与 ANSI)各种编码解码(encode、decode)

    Windows:默认为 ANSI,记事本程序另存为处,可以设置其他编码格式: Ubuntu:默认为 UTF-8 1. ANSI ANSI 编码表示英文字符时用一个字节,表示中文用两个或四个字节 -- ...

  3. B1299 [LLH邀请赛]巧克力棒 博弈论

    这个题一看就是nim游戏的变形.每次先手取出巧克力就是新建一个nim,但假如先手取一个为0的而且无论后手怎么取剩下的都无法为零就行了.然后用dfs跑. 题干: Description TBL和X用巧克 ...

  4. activiti安装-------安装插件

    对上面的放大

  5. 乐字节-Java8核心特性实战之函数式接口

    什么时候可以使用Lambda?通常Lambda表达式是用在函数式接口上使用的.从Java8开始引入了函数式接口,其说明比较简单:函数式接口(Functional Interface)就是一个有且仅有一 ...

  6. python 生成器函数.推导式.生成器表达式

    一.生成器 什么是生成器,生成器的实质就是迭代器 在python中有三种方式来获取生成器: 1.通过生成器函数 2.通过各种推导式来实现生成器 3.通过数据的转换也可以获取生成器 1 def func ...

  7. jQuery使用手册,【新手必备】

    jQuery是一款同prototype一样优秀js开发库类,特别是对css和XPath的支持,使我们写js变得更加方便!如果你不是个js高手又想写出优 秀的js效果,jQuery可以帮你达到目的!   ...

  8. MyBatis分页组件--PageHelper

    一.介绍 PageHelper是国内非常优秀的一款开源的 mybatis 分页插件,它支持基本主流与常用的数据库,例如 Oracle.Mysql.MariaDB.SQLite.Hsqldb 等. 官网 ...

  9. [Android]异常2-Unexpected error while executing

    异常原因: 可能一>Android Studio的自动编译没有成功 解决方法有: 解决一>菜单栏里的“Build”,“Clean Project” 注:

  10. html5——伸缩比例

    基本概念 1.父盒子设置了伸缩属性,子盒子设置伸缩比例 2.以上设置完之后子盒子会按照比例分布在父盒子中 3.当设置伸缩比例时默认会按照x轴方向分配,因为默认情况下伸缩布局主轴方向是x轴方向 4.设置 ...