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 ...
随机推荐
- Java用Gson按照键值key排序json所有节点
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifa ...
- Python 内置函数sorted()在高级用法
对于Python内置函数sorted(),先拿来跟list(列表)中的成员函数list.sort()进行下对比.在本质上,list的排序和内建函数sorted的排序是差不多的,连参数都基本上是一样的. ...
- mysql 通过查看mysql 配置参数、状态来优化你的mysql
我把MYISAM改成了INNODB,数据库对CPU方面的占用变小很多' mysql的监控方法大致分为两类: 1.连接到mysql数据库内部,使用show status,show variables,f ...
- bzoj2152 / P2634 [国家集训队]聪聪可可(点分治)
P2634 [国家集训队]聪聪可可 淀粉质点分治板子 边权直接 mod 3 直接点分治统计出所有的符合条件的点对再和总方案数约分 至于约分.....gcd搞搞就好辣 #include<iostr ...
- JVM优化-JVM参数配置
配置方式: java [options] MainClass [arguments] options - JVM启动参数. 配置多个参数的时候,参数之间使用空格分隔. 参数命名: 常见为 -参数名 参 ...
- linux普通用户提权
tar通配符注入. echo 'echo "chenglee ALL=(root) NOPASSWD: ALL" > /etc/sudoers' > demo.sh e ...
- android样式之按钮&&图片
在drawable-hdpi中添加xml文件 <?xml version="1.0" encoding="utf-8"?> <selector ...
- ajax返回数据
在使用远程js验证检测账户是否存在时,直在发请求后返回值无效,怎样把值返回回来呢重点注意两点 第一点:type不能省略,不能是异步,async: false 第二点:不能在直接请求成功后返回 var ...
- UI自动化(一)html基础
前端的三把利器 HTML:赤裸的一个人 CSS:华丽的衣服 JS/JavaScript:赋予这个人的行为,也就是动起来 DOM 就是将页面变成可操 HTML(超文本标记语言) html代码实际上就是一 ...
- 2018-2019-1 20189206 《Linux内核原理与分析》第七周作业
linux内核分析学习笔记 --第六章 进程的描述和进程的创建 学习重点--子进程的创建以及运行流程 进程描述和进程的创建 操作系统的三大功能--进程管理.内存管理和文件系统. 在linux内核中利用 ...