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. SQL SERVER 语句大全

    ·SQL的简单查询实例教程关键词:SQL语句大全 中文网 整理编辑,经典SQL语句大全(SQL语句大总结),欢迎网友投稿 下列语句部分是Mssql语句,不可以在access中使用.SQL分类:DDL— ...

  2. 【HDU 4864】 Task

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4864 [算法] 贪心 不妨将两个数组分别按x从大到小排序 然后枚举每件物品,选择x值大于该物品的且 ...

  3. 洛谷P2516 [HAOI2010]最长公共子序列

    题目描述 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X="x0,x1,-,xm-1",序列Y=& ...

  4. [Swift通天遁地]七、数据与安全-(18)使用Swift实现原生的MD5加密

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. 数据库得到too many connections”错误信息

    查进程  show processlist删除进程  kill ID查完整sql  show full processlist; 连数据库   MySQL -S /tmp/mysql.sock   或 ...

  6. BZOJ 2300凸包+离线

    思路: 倒着加显然吧  动态维护这个凸包就好了 //By SiriusRen #include <bits/stdc++.h> using namespace std; ; int n,m ...

  7. Mac上随时切换PYTHON版本

    在MAC上,默认安装了python2.*,自己又安装了python3.*:假如我们需要在终端上随时切换python控制台到需要的版本,可以采用下面的方法. 1.用命令   sudo vi ~/.bas ...

  8. Jquery课堂上课了,第一节Jquery选择器$

    Jquery是优秀的Javascrīpt框架,$是jquery库的申明,它很不稳定(我就常遇上),换一种稳定的写法jQuery.noConflict();                   jQue ...

  9. TCP协议滑动窗口(一)——控制大批量数据传输速率

    窗口大小:TCP头中一个16位的域,表示当前可用接受缓冲区大小.在每个TCP对等段连接初始化时,告诉对方自己的窗口大小(不一定是满额,假如满额65201字节,可能暂时通告5840字节).若客户端接受数 ...

  10. 使用Jupter Notebook实现简单的神经网络

    参考:http://python.jobbole.com/82208/ 注:1)# %matplotlib inline 注解可以使Jupyter中显示图片 2)注意包的导入方式 一.使用的Pytho ...