Integer’s Power HDU - 3208(容斥原理)
找出(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(容斥原理)的更多相关文章
- HDU 3208 Integer’s Power
Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...
- hdu 3208 Integer’s Power 筛法
Integer’s Power Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- GCD HDU - 1695 容斥原理(复杂度低的版本)
题意: 让你从区间[a,b]里面找一个数x,在区间[c,d]里面找一个数y.题目上已经设定a=b=1了.问你能找到多少对GCD(x,y)=k.x=5,y=7和y=5,x=7是同一对 题解: 弄了半天才 ...
- - Visible Trees HDU - 2841 容斥原理
题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前 ...
- HDU Integer's Power(容斥原理)
题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后 ...
- 【HDOJ】3208 Integer’s Power
1. 题目描述定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值.所求为区间$[a, b]$的数代入$f$的累加和,即\[\sum_{x=a}^{b} ...
- HDU 4059 容斥原理+快速幂+逆元
E - The Boss on Mars Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796 容斥原理
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 容斥原理 How many integers can you find
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理 纪念一下 TMD看了好久才明白DFS... 先贴代码后解释 #includ ...
随机推荐
- IdentityServer4【Introduction】之包和项目构建
包和项目构建 IdentityServer包含了以下的nuget包: IdentityServer4 nuget | github 这个包包含了IdentityServer核心的组成部分,有对象模型, ...
- [转帖]nginx服务器安装及配置文件详解
nginx服务器安装及配置文件详解 http://seanlook.com/2015/05/17/nginx-install-and-config/ 发表于 2015-05-17 | 更新于: 2 ...
- mysql修改默认端口号后从windows命令行登录
mysql -u root -p -P 大写的P代表端口号,小写的p代表密码
- Partition算法以及其应用详解上(Golang实现)
最近像在看闲书一样在看一本<啊哈!算法> 当时在amazon上面闲逛挑书,看到巨多人推荐这本算法书,说深入浅出简单易懂便买来阅读.实际上作者描述算法的能力的确令人佩服.就当复习常用算法吧. ...
- centso7 安装redmine
一.安装rvm ###安装rvm gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D3 ...
- MyBatis基础:MyBatis动态SQL(3)
1. 概述 MyBatis中动态SQL包括元素: 元素 作用 备注 if 判断语句 单条件分支判断 choose(when.otherwise) 相当于Java中的case when语句 多条件分支判 ...
- Python——Flask框架——模板
一.渲染模板 render_template 函数把Jinja2模板引擎集成到程序中 二.Jinja2变量过滤器 过滤器名 说明 safe 渲染值是不转义 capitalize 把值得首字母转换成大写 ...
- JS--innerHTML属性
innerHTML属性,不是DOM的组成部分(常用) 获取标签里的文本内容,var span=document.getElementById("span").innerHTML; ...
- npm 和package.json 文件
你可能还记得使用vue-cli 创建vue项目.当创建项目完成后,我们进入到项目目录,启动cmd命令窗口,输入npm install,它就会安装一堆东西(依赖),然后再输入npm run dev, 我 ...
- 把当前ubuntu系统做成镜像
把当前ubuntu系统做成镜像 2018年06月19日 15:24:51 还需要再学习一个 阅读数:9720 原文地址: http://community.bwbot.org/topic/167/%E ...