和hdu2204有点像

这题要特别注意精度问题,如pow的精度需要自己搞一下,然后最大的longlong可以设为1<<31

/*
只要求[1,n]范围内的sum即可
那么先枚举幂次k[1,63]
然后求 x^k<=n,x的最大取值sum[i](这里要扩大一下pow的精度)
然后进行容斥,j%i==0,si-=sj
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (ll)1<<31
#define esp 1e-18
ll sum[];
const double inf=1e18+;
/*
ll Pow(ll a,ll b){//防越界的快速幂
ll res=1;
while(b){
if(b%2){
double judge=1.0*inf/res;
if(a>judge)return -1;//必须先判断res*a是否会越界
res=res*a;
}
b>>=1;
if(a>INF && b>0)return -1;//判断a是否越界了
a=a*a;
}
return res;
} ll calc(ll k,ll n){
ll x=(ll)pow(n,1.0/k),t,p;
p=Pow(x,k);
if(p==n)return x;//刚好相等
if(p>n || p==-1) x--;//越界了
else {//判断x是否能再+1
t=Pow(x+1,k);
if(t!=-1 && t<=n)x++;
}
return x;
} */ 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>INF&&b>) return -;
a=a*a;
}
return ans;
}
ll Find(ll x,ll k)//手动扩大pow精度
{
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 solve(ll n){
if(n==)return ;
ll res=,Max=;
memset(sum,,sizeof sum);
sum[]=n;
for(ll k=;k<=;k++){
sum[k]=Find(n,k);//求扩精度后的最大的x
if(sum[k])sum[k]--;//1特判
if(sum[k]==){Max=k;break;}
}
//容斥
for(int j=Max;j>=;j--)
for(int i=;i<j;i++)
if(j%i==)sum[i]-=sum[j];
for(int i=;i<=Max;i++)res+=sum[i]*i;
return res;
} int main(){
ll L,R;
while(cin>>L>>R && R)
cout<<solve(R)-solve(L-)<<endl;
}

容斥原理——hdu3208的更多相关文章

  1. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

  2. hdu2848 Visible Trees (容斥原理)

    题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...

  3. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  4. BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3028  Solved: 1460[Submit][Sta ...

  5. ACM/ICPC 之 中国剩余定理+容斥原理(HDU5768)

    二进制枚举+容斥原理+中国剩余定理 #include<iostream> #include<cstring> #include<cstdio> #include&l ...

  6. HDU5838 Mountain(状压DP + 容斥原理)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5838 Description Zhu found a map which is a N∗M ...

  7. 【BZOJ-2669】局部极小值 状压DP + 容斥原理

    2669: [cqoi2012]局部极小值 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 561  Solved: 293[Submit][Status ...

  8. HDU 2204Eddy's爱好(容斥原理)

    Eddy's爱好 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

随机推荐

  1. 3.7.4 Tri0 and tri1 nets

    Frm: IEEE Std 1364™-2001, IEEE Standard Verilog® Hardware Description Language The tri0 and tri1 net ...

  2. Nginx:413 Request Entity Too Large 的解决方法

    报错信息413 Request Entity Too Large 解决方法: (20M大小,自己调节,根据文件大小.)修改 php 的配置文件 /etc/php5/fpm/php.ini upload ...

  3. Reverses CodeForces - 906E (最小回文分解)

    题意: 给你两个串s和t,其中t是由s中选择若干个不相交的区间翻转得到的,现在要求求出最少的翻转次数以及给出方案. 1≤|s|=|t|≤500000 题解: 我们将两个字符串合成成T=s1t1s2t2 ...

  4. NFS服务器简易安装

    1.服务端 创建挂载目录 # mkdir /data/nfs 安装NFS软件 # yum install nfs-utils -y 添加配置信息 # vim /etc/exports /data/nf ...

  5. Springboot整合dubbo搭建基本的消费、提供和负载均衡

    文章目录 1.确定接口 2.创建提供者 2.1 pom配置 2.2dubbo配置文件 2.3 application.properties 2.4 mybatis相关 2.4.1 配置UserMapp ...

  6. sql 保存,性能高

    INSERT INTO TABLE( Id, Name) VALUES ( 4, 'A'), ( 5, 'P' ),( 6, 'U') ; INSERT INTO TABLE( Id, Name) S ...

  7. PostGIS 通过SQL语句实现空间分析【入门级】

    PostGIS是对象关系型数据库系统PostgreSQL的一个扩展,PostGIS提供如下空间信息服务功能:空间对象.空间索引.空间操作函数和空间操作符.同时,PostGIS遵循OpenGIS的规范. ...

  8. 【笔记篇】斜率优化dp(四) ZJOI2007仓库建设

    传送门戳这里>>> \(n\leq1e6\), 显然还是\(O(n)\)的做法. 这个题有个条件是只能运往编号更大的工厂的仓库, 这也是写出朴素dp的方程的条件. 我们令\(f[i] ...

  9. Leetcode274.H-IndexH指数

    原题的中文翻译不是很好,所以给出英文版. Given an array of citations (each citation is a non-negative integer) of a rese ...

  10. artTemplate(mark)

    一个渲染性能出众模板引擎,无论在 NodeJS 还是在浏览器中都可以运行. 特性 拥有接近 JavaScript 渲染极限的的性能 调试友好:语法.运行时错误日志精确到模板所在行:支持在模板文件上打断 ...