hdu 3208 简单容斥原理
2015-10-12 00:23
330 查看
好题。
学会了一种处理溢出的技巧。。from acdreamer's blog
code:
学会了一种处理溢出的技巧。。from acdreamer's blog
code:
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <cmath> using namespace std; #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,n,a) for (int i=n;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define fi first #define se second typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; ll powmod(ll a,ll b) {ll res=1;for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;} #define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0) ll n; const ll T = (ll)1LL<<31; const ll INF = 1e18 + 300; ll num[100]; ll multi(ll a, ll b){ ll res = 1; while(b){ if(b&1){ double tmp = 1.0*INF/res; if(a > tmp) return -1; res *= a; } b>>=1; if(b > 0 && a > T) return -1; a *= a; } return res; } ll find(ll x, ll k){ ll tmp = pow(x, 1.0/k); ll p = multi(tmp, k); if(p == x) return tmp; if(p == -1 || p > x) return tmp-1; else{ ll t = multi(tmp+1, k); if(t != -1&&t<=x) tmp++; } return tmp; } ll solve(ll x){ memset(num, 0, sizeof(num)); num[1] = x; for(int i = 2; i<=60; i++) num[i] = find(x, i)-1; for(int i=60; i>=1; i--) for(int j=i+1; j<=60; j++) if(j%i==0) num[i] -= num[j]; ll res = 0; for(int i=1; i<=60; i++) res += num[i]*i; return res; } ll a,b; int main(){ while(cin>>a>>b&&a+b){ ll res = solve(b) - solve(a-1); printf("%lld\n", res); } return 0; }
相关文章推荐
- hdu 4059 小学生容斥
- poj 3904 容斥原理
- Mining Massive Datasets课程笔记(三)
- PHP第一季视频教程.李炎恢.学习笔记(五)(第3章 操作符与控制结构(1)(2))
- TypeLoadException: 找不到 Windows 运行时类型“Windows.UI.Xaml.Controls.Binding
- Chapter 3-03
- 微软代码签名证书使用指南
- Chapter 9-MaxHeap
- Chapter 8-BinaryTree
- Best Time to Buy and Sell Stock
- 在安装vmtools的时候老是提示sudo: ./vmware-install.pl找不到命令。
- 常用Keytool 命令
- 百事可乐要做手机,还能不能好好喝饮料了?
- Java基础知识总结
- linux下静态库的入门用法
- CentOS下MySQL的彻底卸载
- cf 状压dp Little Pony and Harmony Chest
- 关于图片拉伸的技巧
- 设计模式--迪米特法则
- 内存管理