【TCO2A ThePowers】容斥原理
来源:互联网 发布:windows hadoop2 安装 编辑:程序博客网 时间:2024/05/18 00:24
Description
对于
Difficulty
MainAlgorithm
容斥原理
Complexity
Solution
考虑两个数的次幂得到了相同结果,
则
那么
我们发现,只有有着共同的
即
那么就变为
由于不同的 x 能达到的数不同,为了方便处理,我们分别处理
注意到假如
那么通过容斥暴力把这部分算出来。
再从
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define Rep(i, x, y) for (int i = x; i <= y; i ++)#define Dwn(i, x, y) for (int i = x; i >= y; i --)#define RepE(i, x) for(int i = pos[x]; i; i = g[i].nex)using namespace std;typedef long long LL;const int mx = 30, M = 50;class ThePowers {public:LL f[M], ans, ql, qr, u[M], uz, A, B;int qk;LL gcd(LL x, LL y) {return !y ? x : gcd(y, x % y);}void Dfs(int x, LL lm, int o, int t) {if (x == uz + 1) {if (!t) return ;LL ret = qr / lm - (ql-1) / lm;f[qk] += ret * o;return ;}Dfs(x + 1, lm * u[x] / gcd(lm, u[x]), o * (-1), t + 1);Dfs(x + 1, lm, o, t);}LL find (int A0, int B0) {A = A0, B = B0;for (qk = 1; qk <= mx; qk ++) { // prepare to all the g^k 's k ..Rep(i, 1, qk) {ql = (i - 1) * B + 1, qr = i * B, uz = 0;Rep(j, i, qk) {bool fl = 0;Rep(o, i + 1, j - 1) if (j % o == 0) fl = 1;if (!fl) u[++ uz] = j;}Dfs(1, 1, -1, 0);}}LL la = A - 1;for (int i = 2; i * i <= A; i ++) {int k = i, o, g0 = 0;for (int j = 2; j * j <= k; j ++) {o = 0;while (k % j == 0) o ++, k /= j;if (o) g0 = gcd(g0, o);}if (k > 1) g0 = 1;if (g0 <= 1) {int r = 1; LL k = i;while (k * i <= A) r ++, k *= i;ans += f[r];la -= r;}}return ans + 1 + la * B;}};
0 0
- 【TCO2A ThePowers】容斥原理
- 容斥原理
- 容斥原理 POJ3904
- 【容斥原理】八
- 【八】容斥原理
- 广义容斥原理
- 容斥原理
- 容斥原理 专题
- 容斥原理 专题
- hdu4390 容斥原理
- hdu1695 容斥原理
- HDU3929(容斥原理)
- 整除 容斥原理
- HDU4390(容斥原理)
- 容斥原理
- poj3904 容斥原理
- 容斥原理应用
- bzoj2393 容斥原理
- 梯度下降
- 几张图看懂列式存储
- SQL Server2008恢复模式、简单恢复模式、完整恢复模式、大容量日志恢复模式
- [leetcode] #8 String to Integer (atoi)
- 年轮
- 【TCO2A ThePowers】容斥原理
- ArrayList和LinkedList的几种循环遍历方式及性能对比分
- 第14章 高级I/O
- 对button更深层次的研究 详解
- Greenplum服务器配置参数
- VVDocumenter-Xcode不能用
- usb 接口突然不能使用了怎么办?
- mysql局域网访问设置
- sizeof枚举类型大小详解