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 ...
随机推荐
- GUI带有右键菜单,带有时间显示的
%带有右键菜单的GUI figure('Menubar','none'); h = uicontextmenu; uimenu(h,'Label','A'); uimenu(h,'Label','B' ...
- Android平台MediaCodec避坑指北
https://www.jianshu.com/p/5d62a3cf0741 最近使用MediaCodec做编解码H264,写一点东西以免自己再次掉坑. 先说一下具体环境,使用的是,Windows10 ...
- 学写网页 #06# table
A B E C D <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...
- php 获取最近一周,一个月,一年
<?php date_default_timezone_set('PRC'); /** * 获取最近一周,一个月,一年 * */ function getLatelyTime($type = ' ...
- JDK常用命令(三)jmap
jmap jmap,Java Memory Map.主要用于打印指定Java进程(或核心文件.远程调试服务器)的共享对象内存映射或堆内存细节. jmap命令可以获得运行中的jvm的堆的快照,从而可以离 ...
- 在见证了1000多家公司的兴衰灭亡之后,YC创始合伙人总结了创业公司的6个不死法则(转)
今天,我想先说一下个人消息.在 YC 工作了 11 年之后,我明年想去休假.我希望把精力放在一些项目上,说实话,我有点累了. YC 是这世界上我最喜欢的事情之一,但它也很费精力. 11 年不间断的耗费 ...
- 2、pandas的value_counts()和describe()
一.value_counts pandas 的value_counts()函数可以对Series里面的每个值进行计数并且排序. value_counts是计数,统计所有非零元素的个数,默认以降序的方式 ...
- vue.JS 介绍
vueJS 介绍 首先,vueJS 是我很早之前就想要接触学习的东西,但是呢,一直没时间,主要是在学校,事太多,没心思定下心来学习,我学生生涯的最后一个假期的第一天晚上,万事开头难,那就先写点儿什么东 ...
- 【python018--函数参数】
1.形参和实参 >>> def MyFirstFunction(name): '函数定义过程中的name是叫形参' #因为Ta只是一个形式,表示占据一个参数位置 p ...
- 网络 --- 1 c/s (b/s)架构 ip 初始socket
一.c/s b/s c/s架构:客户端(client)/服务器(server) 软件cs架构:微信,陌陌,qq等 硬件cs架构:打印机 b/s架构:浏览器(browser)/服务器(server) ...