hdu 3208 Integer’s Power 筛法
Integer’s Power
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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?
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.
248832 248832
0 0
5
思路:卡精度;
#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
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?
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.
248832 248832
0 0
5
hdu 3208 Integer’s Power 筛法的更多相关文章
- HDU 3208 Integer’s Power
Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...
- 【HDOJ】3208 Integer’s Power
1. 题目描述定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值.所求为区间$[a, b]$的数代入$f$的累加和,即\[\sum_{x=a}^{b} ...
- Integer’s Power HDU - 3208(容斥原理)
找出(l,r)内的所有的指数最大的次方和 因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉. 然后开n方的部分,先用pow()函数找到最接 ...
- HDU Integer's Power(容斥原理)
题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后 ...
- hdu 1047 Integer Inquiry
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...
- hdu 6034 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
- HDU 4461:The Power of Xiangqi(水题)
http://acm.hdu.edu.cn/showproblem.php?pid=4461 题意:每个棋子有一个权值,给出红方的棋子情况,黑方的棋子情况,问谁能赢. 思路:注意“ if a play ...
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 4658 Integer Partition(整数拆分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:给出n.k.求n的拆分方案数.要求拆分中每个数不超过k. i64 f[N]; void i ...
随机推荐
- 源码下载:74个Android开发开源项目汇总
1. ActionBarSherlock ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便地使用所 ...
- ul点击li,增加样式
用户首次绑定后,需要选择一款头像 <!--imgList头像列表--><el-row class="regModel1"> <el-col :span ...
- P1216 数字金字塔
P1216 数字金字塔 我们可以用 f [ i ] [ j ] 表示从(1,1)出发,到达(i,j)的最大权值和. (i , j)可以由(i - 1 , j)或者(i - 1 , j - 1)转化来 ...
- java之异常统一处理
spring-mvc.xml <!-- aop --> <aop:aspectj-autoproxy/> <beans:bean id="controllerA ...
- 大数据自学2-Hue集成环境中使用Sqoop组件从Sql Server导数据到Hive/HDFS
安装完CDH后,发现里面的东东实在是太多了,对于一个初学大数据的来说就犹如刘姥姥进了大观园,很新奇,这些东东每个单拿出来都够喝一壶的. 接来来就是一步一步地学习了,先大致学习了每个模组大致做什么用的, ...
- 每日linux命令学习-grep模式检索
grep模式检索指令包括grep,egrep,和fgrep,.Linux系统使用正则表达式优化文本检索,所以在此,笔者首先学习了一下正则表达式. 1. 正则表达式 正则表达式使用被称为元字符(Meta ...
- Java连接数据库 #04# Apache Commons DbUtils
索引 通过一个简单的调用看整体结构 Examples 修改JAVA连接数据库#03#中的代码 DbUtils并非是什么ORM框架,只是对原始的JDBC进行了一些封装,以便我们少写一些重复代码.就“用” ...
- Lyft高管的技术团队管理实战
Lyft 的技术总监沈思维分享了他对于管理技术团队和打造工程文化的经验,也欢迎添加他的微信公众号"人家的屋顶"了解更多(微信公众号ID: othersroof).沈思维毕业于密歇根 ...
- 关于actor模型
actor model是1973年就提出的一个分布式并发编程模型,在erlang语言中得到广泛支持和应用.目前Java中也出现了很多支持actor模型的库:akka.killim.jetlang等等, ...
- spring boot 结合Redis 实现工具类
自己整理了 spring boot 结合 Redis 的工具类引入依赖 <dependency> <groupId>org.springframework.boot</g ...