凯牛大爹吧 关注:146贴子:39,320
  • 5回复贴,共1

前来拜大爹

只看楼主收藏回复

偷偷存点东西,手机不方便
扼要解析:
我做错杂了, 于是这个做法就是:
重视到f(x)的值是小于64的, 我们就可以统计出[l, r]区间内的1次方数, 2次方数直至63次方数(并不是严格2次方, 可以包含4次方等). 令p[x]记录x次方数的个数, 如今我们推敲如何求恰为1次方数的数的个数. 很明显可以哄骗容斥道理, 答案就是p[1] - p[2] - p[3] - p[5] + p[6] - p[7] + p[10] - ..., 每一项的系数恰为该数的莫比乌斯函数(详见wiki). 对于其它的次数, 被它包含的只可能是它的倍数, 所以把这些数都除以你要统计的那个次数, 就回到刚才评论辩论的恰为1次的题目了. 时候错杂度O(64 ^ 2).
代码实现:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#ifdef unix
#define FMT "%lld"
#else
#define FMT "%I64d"
#endif
typedef long long val_t;
const val_t INF = 1000000000000000000LL;
val_t a, b;
val_t p[64], q[64];
bool vis[64];
int pr[64], f[64];
val_t power(val_t a, int b) {
if (!b) return 1;
val_t ret = power(a, b >> 1);
ret = ret * ret;
if (b & 1) ret = ret * a;
return ret;
}
void get_pr() {
f[1] = 1;
for (int i = 2; i < 64; i ++) {
if (!vis[i]) {
pr[++ pr[0]] = i;
f[i] = -1;
}
for (int j = 1, k; j <= pr[0] && (k = pr[j] * i) < 64; j ++) {
vis[k] = 1;
int c = 0, x = k;
while (x % pr[j] == 0) x /= pr[j], c ++;
if (c > 1) f[k] = 0;
else f[k] = f[x] * (-1);
if (i % pr[j] == 0) break;
}
}
}
int main() {
get_pr();
q[1] = INF;
for (int i = 2; i < 64; i ++) q[i] = (val_t)(floor(1E-6 + exp(1.0 / i * log((double)INF))));
while (scanf(FMT FMT, &a, &b) != EOF) {
if (a == 0) break;
memset(p, 0, sizeof(p));
p[1] = b - a + 1;
for (int i = 2; ; i ++) {
if (q[i] == 1) break;
val_t l, r, lb, rb, mid;
lb = 0, rb = q[i];
while (lb + 1 < rb) {
mid = (lb + rb) >> 1;
if (power(mid, i) >= a) rb = mid;
else lb = mid;
}
l = rb;
lb = 1, rb = q[i] + 1;
while (lb + 1 < rb) {
mid = (lb + rb) >> 1;
if (power(mid, i) <= b) lb = mid;
else rb = mid;
}
r = lb;
if (l <= r && power(l, i) >= a && power(r, i) <= b) p[i] = r - l + 1;
}
val_t ans = 0LL;
for (int i = 1; i < 64; i ++) {
val_t x = 0LL;
for (int j = 1; j * i < 64; j ++) x += f[j] * p[j * i];
ans += x * i;
}
printf(FMT "\n", ans);
}
return 0;
}


IP属地:浙江来自手机贴吧1楼2014-11-13 09:31回复
    偷偷orz


    IP属地:山东2楼2014-11-14 13:47
    收起回复
      前排强行膜拜


      IP属地:浙江3楼2014-11-19 21:55
      回复
        偷偷orz


        IP属地:上海4楼2014-11-24 17:46
        回复