找出(l,r)内的所有的指数最大的次方和

因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉。

然后开n方的部分,先用pow()函数找到最接近答案的数,但是会丢失精度,然后在这个数的附近寻找最接近答案的整数,用快速幂在乘n次幂回去,看最接近原本数的是哪一个。

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
const int mod = ;
const double eps = 1e-;
using namespace std; ll n, m;
int T, tol;
ll num[];
ll INF = 1e18; ll qpow(ll a, ll b) {
ll ans = ;
while(b) {
if(b&) {
double tmp = 1.0 * INF / ans;
if(a > tmp) return -;
ans = ans * a;
}
b >>= ;
if(a > ((ll)<<) && b) return -;
a = a*a;
}
return ans;
} ll calc(ll x, int pos) {
ll a = (ll)pow((double)x, 1.0/pos);
ll ansl = qpow(a-, pos);
ll ansm = qpow(a, pos);
ll ansr = qpow(a+, pos);
if(ansr != - && ansr <= x) return a+;
if(ansm != - && ansm <= x) return a;
return a-;
} ll solve(ll x) {
memset(num, , sizeof num);
num[] = x;
int pos = ;
for(; pos <= ; pos++) {
ll tmp = calc(x, pos) - ;
if(tmp <= ) break;
num[pos] = tmp;
}
pos--;
for(int i=pos; i>=; i--) {
for(int j=; i*j<=pos; j++) {
num[i] -= num[i*j];
}
}
//for(int i=1; i<=pos; i++) printf("%I64d%c", num[i], i==pos ? '\n' : ' ');
ll ans = ;
for(int i=; i<=pos; i++) ans += i * num[i];
return ans;
} int main() {
while(scanf("%I64d%I64d", &n, &m), n||m) {
ll ans = solve(m);
ans -= solve(n-);
printf("%I64d\n", ans);
}
return ;
}

Integer’s Power HDU - 3208(容斥原理)的更多相关文章

  1. HDU 3208 Integer’s Power

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

  2. hdu 3208 Integer’s Power 筛法

    Integer’s Power Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. GCD HDU - 1695 容斥原理(复杂度低的版本)

    题意: 让你从区间[a,b]里面找一个数x,在区间[c,d]里面找一个数y.题目上已经设定a=b=1了.问你能找到多少对GCD(x,y)=k.x=5,y=7和y=5,x=7是同一对 题解: 弄了半天才 ...

  4. - Visible Trees HDU - 2841 容斥原理

    题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前 ...

  5. HDU Integer's Power(容斥原理)

    题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后 ...

  6. 【HDOJ】3208 Integer’s Power

    1. 题目描述定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值.所求为区间$[a, b]$的数代入$f$的累加和,即\[\sum_{x=a}^{b} ...

  7. HDU 4059 容斥原理+快速幂+逆元

    E - The Boss on Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796 容斥原理

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. HDU 1796 容斥原理 How many integers can you find

    题目连接   http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理  纪念一下  TMD看了好久才明白DFS... 先贴代码后解释 #includ ...

随机推荐

  1. myeclipse部署报错报空指针异常

    hib4.1+spring3+struts2项目 项目运行报错,把WEB-INF/classes目录删除后,想再重新编译并自动部署.再自动部署时总是提示错误: Errors occurred duri ...

  2. Oracle数值函数

    --数值函数 --四舍五入 ) from dual ) from dual --数字截取 ) from dual --取模 ,) from dual

  3. Flutter的输入框TextField

    TextFiled组件的API 先来看一下TextFiled的构造方法: const TextField({ Key key, this.controller, this.focusNode, thi ...

  4. php7函数,声明,返回值等新特性介绍

    使用 ... 运算符定义变长参数函数 (PHP 5 >= 5.6.0, PHP 7) 现在可以不依赖 func_get_args(), 使用 ... 运算符 来实现 变长参数函数. functi ...

  5. python数学第十天【最大似然估计】

  6. php配置-解决大数据超多字段的POST方式提交无法完全接受的问题

    例如:在盘点表的数据提交中出现了POST大量数据超多字段的将近2000个字段,部分字段没有接受:修改方法为修改php.ini 将max_input_var调大,该值默认为1000 max_input_ ...

  7. Java使用RabbitMQ之消息确认(confirm模板)

    RabbitMQ生产者消息确认Confirm模式,分为普通模式.批量模式和异步模式,本次举例为普通模式. 源码: package org.study.confirm4; import com.rabb ...

  8. js对日期的判断

    在初始页面获取倒当前时间并向前推N天后作为起始时间       function date(){          var myDate = new Date();          //获取当前时间 ...

  9. 学习 Spring (十三) AOP 配置

    Spring入门篇 学习笔记 Spring 所有的切面和通知器都必须放在一个 内(可以配置包含多个 元素),每一个 可以包含 pointcut, advisor 和 aspect 元素(它们必须按照这 ...

  10. Using MongoDB with Web API and ASP.NET Core

    MongoDB is a NoSQL document-oriented database that allows you to define JSON based documents which a ...