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. Gym - 101208C 2013 ACM-ICPC World Finals C.Surely You Congest 最大流+最短路

    题面 题意:给你n(2w5)个点,m条边(7w5)有k(1e3)辆车停在某些点上的,然后他们都想尽快去1号点,同时出发,同一个点不允许同时经过, 如果多辆车同时到达一个点,他们就会堵塞,这时候只能选择 ...

  2. [Swift通天遁地]九、拔剑吧-(7)创建旋转和弹性的页面切换效果

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

  3. 网络简要<入门篇>

    OSI七层 网络的含义:两个不在同一地理位置的主机(终端),通过传输介质和通信协议,实现通信和资源共享. 网络四要素:终端,传输介质 ,通信协议,资源 网络分类: 以范围分类:LAN网(局域网,以太网 ...

  4. hadoop一主一从部署(1)

    一.安装前说明 主机IP:192.168.132.128 从机IP:192.168.132.129 1. 所有的安装包我放在了/root/这个目录下,你要根据自己情况去修改,这点必须注意 2. 采用的 ...

  5. 【NOIP练习赛】学习

    [NOIP练习赛]T3.学习 Description 巨弱小 D 准备学习,有 n 份学习资料给他看,每份学习资料的 内容可以用一个正整数 ai 表示.小 D 如果在一天内学习了多份资料, 他只能记住 ...

  6. js的toFixed解惑

    js中的toFixed,C#中的Math.round都是按照银行家算法的定义来算的,这里只拿js作参考,各个浏览器的计算方式并不一样,先看一张图,对比参数很容易就发现了其中的不同之处: 前三个Chro ...

  7. SQL Sever语言 存储过程及触发器

    存储过程:就像函数一样的会保存在数据库中-->可编程性-->存储过程 创建存储过程: 保存在数据库表,可编程性,存储过程create proc jiafa --需要的参数@a int,@b ...

  8. [ POI 2011 ] Dynamite

    \(\\\) \(Description\) 一棵\(N\)个节点的树,树上有\(M\)个节点是关键点,选出\(K\)个特殊点,使得所有关键点到特殊点的距离中最大的最小,输出最大值最小为多少. \(N ...

  9. PHP第二阶段学习 一、php的基本语法

    php的基本语法 输出语句:a.  echo输出:可以输出多个字符串,逗号隔开 b.  print输出:只能输出一个字符串,返回true或false c.  print_r():可以把字符串和数字简单 ...

  10. 初始MongoDB------MongoDB的安装

    MongoDB在Windows的安装是很简单的,无论是安装包还是绿色包,安装出来的都是这些文件   重点是Bin中的东西   特别是前两个的执行文件 mongod进程就是启动MongoDB数据库的进程 ...