1. 题目描述
定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值。所求为区间$[a, b]$的数代入$f$的累加和,即
\[
\sum_{x=a}^{b} f(x)
\]
2. 基本思路
因为数据很大, 因此不适合暴力枚举。但是对于给定的数$y$,我们可以求得$x^k \le y$。假设$x^k$均不相同,那么直接可解。
因为存在$2^4 = 4^2$的情况,因此,这里其实是个容斥。即$c[i]$的数值应该减掉$c[k \cdot i]$的数值。由于数据一定不超过$2^{63}$,
故对于给定的数$y$,我们可以求得$\{|x| | x^k \le y, k \in [2, 63]\}$然后使用容斥去掉非最优解的情况。

3. 代码

 /* 3208 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef long long LL;
double inf = 1e18 + ;
double bound = 5e18 + ;
LL c[];
LL a, b; LL Pow(LL base, LL n) {
LL ret = ; while (n) {
if (n & ) {
if (inf/base < ret) return -;
ret = ret * base;
} n >>= ;
if (bound/base<base && n>) return -;
base = base * base;
} return ret;
} LL gao(LL v, LL n) {
LL x = pow((double)v, 1.0/n);
LL tmp = Pow(x, n);
if (tmp == v) return x;
if (tmp>v || tmp==-) {
--x;
} else {
tmp = Pow(x+, n);
if (tmp!=- && tmp<=v) ++x;
} return x;
} LL calc(LL n) {
int i; memset(c, , sizeof(c));
c[] = n;
for (i=; i<; ++i) {
c[i] = gao(n, i) - ;
if (c[i] == ) break;
} per(j, , i) {
rep(k, , j) {
if (j%k == )
c[k] -= c[j];
}
} LL ret = ;
rep(j, , i) ret += j*c[j];
return ret;
} void solve() {
LL ans = calc(b) - calc(a-);
printf("%I64d\n", ans);
} int main() {
cin.tie();
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%I64d%I64d", &a,&b)!=EOF && (a||b)) {
solve();
} #ifndef ONLINE_JUDGE
printf("time = %ldms.\n", clock());
#endif return ;
}

【HDOJ】3208 Integer’s Power的更多相关文章

  1. 【LeetCode】397. Integer Replacement 解题报告(Python)

    [LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/inte ...

  2. HDU 3208 Integer’s Power

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

  3. hdu 3208 Integer’s Power 筛法

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

  4. 【HDOJ】Power Stations

    DLX.针对每个城市,每个城市可充电的区间构成一个plan.每个决策由N*D个时间及N个精确覆盖构成. /* 3663 */ #include <iostream> #include &l ...

  5. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  6. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  7. 【HDOJ】4426 Palindromic Substring

    综合性很强的一道题目,结合manacher,后缀数组,哈希,RMQ,二分可解.基本思路是通过manacher可以找到所有可能的回文串,哈希去重,后缀数组二分找数目.最后暴力求解.需要注意kth需要为_ ...

  8. 【PAT】1103 Integer Factorization(30 分)

    The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positi ...

  9. 【leetcode】Reverse Integer(middle)☆

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 总结:处理整数溢出 ...

随机推荐

  1. Mac上安装 mySql

    今天在mac系统上安装了 mySql 和大家分享下 安装的过程.. 首先 第一步 需要在oracle的网站下载 mysql 的mac 版本. 下载地址如下: http://www.mysql.com/ ...

  2. zoj 2314 Reactor Cooling 网络流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 The terrorist group leaded by a ...

  3. Poj 1050 分类: Translation Mode 2014-04-04 09:31 103人阅读 评论(0) 收藏

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39058   Accepted: 20629 Desc ...

  4. 【转载】c/c++在windows下获取时间和计算时间差的几种方法总结

    一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double difftime( time_t timer1, time_t time ...

  5. 项目分析 NGPcontext

    NGPcontext 之前对这个一直很疑惑,我一直认为只是在机器人方面有用处,但很有疑问,正在做这方面,我想好好看看到底是怎么运行的 bool NGP::init(NGPcontext context ...

  6. rpc 小例子

    RpcFramework /* * Copyright 2011 Alibaba.com All right reserved. This software is the * confidential ...

  7. IE8中能继续使用Expression的解决方案

    在实际工作中,长的报表需要固定表头,比如DataGrid等控件. 过去在用IE8以前版本的时候,只需要在css中加上 position:relative ; top:expresion(this.of ...

  8. javascript笔记 面向对象

    Javascript是一种面向对象的弱语言,既然有面向对象,就有继承 继承: 1.call函数和apply函数:区别在于它们参数上的不同,固定参数的用call,可变参数的用apply.换句话说,就是a ...

  9. VS2010中出现无法嵌入互操作类型

    针对word或excel操作时,出现VS2010中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法 问了度娘,解决方法如出一辙:选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型” ...

  10. HDU 1116 || POJ 1386 || ZOJ 2016 Play on Words (欧拉回路+并查集)

    题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有 ...