Integer’s Power

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
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

思路:卡精度;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e4+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; LL big[]={,,,,};
const LL T=(LL)<<; LL multi(LL a,LL b)
{
LL ans=;
while(b)
{
if(b&)
{
double judge=1.0*INF/ans;
if(a>judge) return -;
ans*=a;
}
b>>=;
if(a>T&&b>) return -;
a=a*a;
}
return ans;
} LL findd(LL x,LL k)
{
LL r=(LL)pow(x,1.0/k);
LL t,p;
p=multi(r,k);
if(p==x) return r;
if(p>x||p==-) r--;
else
{
t=multi(r+,k);
if(t!=-&&t<=x) r++;
}
return r;
}
LL dp[];
LL xjhz(LL x)
{
memset(dp,,sizeof(dp));
dp[]=x-;
for(int i=;i<=;i++)
{
int s=,e=big[i],ans=-;
while(s<=e)
{
int mid=(s+e)>>;
if(multi(mid,i)<=x)
{
ans=mid;
s=mid+;
}
else e=mid-;
}
if(ans!=-)dp[i]=ans-;
}
for(int i=;i<=;i++)
{
dp[i]=findd(x,i)-;
}
for(int i=;i>=;i--)
{
for(int j=i+i;j<=;j+=i)
dp[i]-=dp[j];
}
LL out=;
for(int i=;i<=;i++)
out+=1LL*i*dp[i];
return out;
}
int main()
{
LL l,r;
while(~scanf("%lld%lld",&l,&r))
{
if(l==&&r==)break;
printf("%lld\n",xjhz(r)-xjhz(l-));
}
return ;
}

Integer’s Power

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2291    Accepted Submission(s): 516

Problem Description
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

hdu 3208 Integer’s Power 筛法的更多相关文章

  1. HDU 3208 Integer’s Power

    Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...

  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. Navicat连接MySQL8.0亲测有效

    今天下了个 MySQL8.0,发现Navicat连接不上,总是报错1251: 原因是MySQL8.0版本的加密方式和MySQL5.0的不一样,连接会报错. 试了很多种方法,终于找到一种可以实现的: 更 ...

  2. TCP/IP协议三次握手与四次挥手

    一.标志位和序号 seq序号 :发送方随机生成的 ack确认序号:ack=seq+1 标志位ACK=1时确认序号有效 SYN标志位:发起一个新连接 ACK标志位:确认序号有效 FIN标志位:断开连接 ...

  3. python-selenium,关于页面滑动的操作

    //移动到元素element对象的“顶端”与当前窗口的“顶部”对齐 ((JavascriptExecutor) driver).executeScript("arguments[0].scr ...

  4. Java中五种遍历HashMap的方式

    import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class Java8Templat ...

  5. DBeaver连接Oracle11g数据库

    DBeaver连接Oracle11g数据库 一.准备 (1)dbeaver管理软件 (2)远程连接数据库地址.用户名秘密等 (3)Oracle驱动:ojdbc6.jar工具包 下载地址:https:/ ...

  6. MD5算法详解

    MD5是什么 message-digest algorithm 5(信息-摘要算法).经常说的“MD5加密”,就是它→信息-摘要算法.在下载一下东西时,经常在一些压缩包属性里,看到md5值.而且这个下 ...

  7. 《C Elements of Style》 书摘

    <C Elements of Style> 书摘 学完C语言和数据结构后,虽然能解决一些问题,但总觉得自己写的程序丑陋,不专业.这时候看到了Steve Oualline写的<C El ...

  8. ubuntu+anaconda+tensorflow 及相关问题

    配置tensorflow部分参考:https://blog.csdn.net/XUTIAN1129/article/details/78997633 装完anaconda, source ~/.bas ...

  9. c++中ifstream一次读取整个文件

    转载:http://www.cnblogs.com/kex1n/p/4028428.html 第一种方法: 读取至std::string的情况: #include <string> #in ...

  10. topcoder srm 505 div1

    problem1 link 设行数为$n$列数为$m$ 对于任意的两行$r_{1},r_{2}$以及任意的两列$c_{1},c_{2}$所确定的四个格子,只要知道其中的三个就能确定第四个,且必须要三个 ...