求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$。

首先,假定$(x, n)=m$,那么 $(\frac{x}{n},\frac{n}{m})=1$,故$$ans=\sum_{i=m}^{n}\varphi(\frac{n}{i})$$

ん?遅い!

$$\sum_{i=m}^{n}\varphi(\frac{n}{i})=\sum\limits_{d|n}{\varphi(\frac{n}{d})}$$

其实还可以再优化下的吧?

/** @Date    : 2017-09-20 21:55:29
* @FileName: HDU 2588 思维 容斥 或 欧拉函数.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL pri[N];
int vis[N];
int c = 0; void prime()
{
MMF(vis);
for(int i = 2; i < N; i++)
{
if(!vis[i]) pri[c++] = i;
for(int j = 0; j < c && i * pri[j] < N; j++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0) break;
}
}
} LL get_phi(LL x)
{
LL ans = x;
for(int i = 0; i < c && pri[i] <= x / pri[i]; i++)
{
if(x % pri[i] == 0)
{
while(x % pri[i] == 0)
x /= pri[i];
ans = ans / pri[i] * (pri[i] - 1);
}
}
if(x > 1)
ans = ans / x * (x - 1);
return ans;
} int main()
{
int T;
cin >> T;
prime();
while(T--)
{
LL n, m;
scanf("%lld%lld", &n, &m);
LL t = n;
LL ans = 0;
for(LL i = 1; i <= t / i; i++)
{
if(t % i == 0)
{
//cout << i << t/i << endl;
if(i >= m)
ans += get_phi(n / i);
if(t / i != i && t / i >= m)
ans += get_phi(n / (t / i));
}
}
printf("%lld\n", ans);
}
return 0;
}

HDU 2588 思维 容斥的更多相关文章

  1. hdu 5514 Frogs(容斥)

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  2. HDU 5213 分块 容斥

    给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...

  3. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  4. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  5. hdu 5768 Lucky7 容斥

    Lucky7 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...

  6. HDU - 4407 Sum (容斥)

    题意:初始序列[1..N](1<=N<=4e5),支持两种操作:1.求区间[x,y]内与p互素的数之和: 2.将x位置的数变为c. 分析:很容易把人骗到线段树的思维中,而实际上操作2单点的 ...

  7. hdu 5212 反向容斥或者莫比

    http://acm.hdu.edu.cn/showproblem.php?pid=5212 题意:忽略.. 题解:把题目转化为求每个gcd的贡献.(http://www.cnblogs.com/z1 ...

  8. ACM-ICPC 2015 沈阳赛区现场赛 F. Frogs && HDU 5514(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意:有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过xi个石子.问所 ...

  9. hdu 1695 GCD 容斥+欧拉函数

    题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, ...

随机推荐

  1. c# 加载图片 正在被占用问题

    问题情境:图片文件加载到pdf中,程序没有退出,再次加载该图片文件,提示被占用. 解决办法: 1.加载文件会锁定该文件,fromfile方法会导致占用内存较大,不使用该方法. FileStream f ...

  2. HDU 5183 Negative and Positive (NP) 前缀和+哈希

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5183 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  3. SSL 重点SSL会话步骤

    SSL.TLS协议 在wiki百科查看下,两者的区别 实现SSL协议的软件 OpenSSL开源软件 SSL会话步骤 1:客户端向服务端索取CA证书,然后验证证书   2:客户端与服务端约定一个通信中使 ...

  4. Java第一次笔记

  5. Viewpoint Meta标签

    移动web Viewpoint常用得设置方式: [布局viewpoint] = [设备宽度] = [度量viewpoint] <meta name="viewport" co ...

  6. 【C++】构造函数不能是虚函数

    1 虚函数对应一个vtable,这大家都知道,可是这个vtable其实是存储在对象的内存空间的.问题出来了,如果构造函数是虚的,就需要通过 vtable来调用,可是对象还没有实例化,也就是内存空间还没 ...

  7. 【明哥报错簿】之 mybatis异常invalid comparison: java.util.Date and java.lang.String

    背景:数据库为postgresql,表字段属性为timestamp格式 原因是mybatis 3.3.0中对于时间参数进行比较时的一个bug. 如果拿传入的时间类型参数与空字符串''进行对比判断则会引 ...

  8. [二十三]SpringBoot 之 redis

    本文章牵涉到的技术点比较多:spring Data JPA.Redis.Spring MVC,Spirng Cache,所以在看这篇文章的时候,需要对以上这些技术点有一定的了解或者也可以先看看这篇文章 ...

  9. 洛谷 [POI2007]BIU-Offices 解题报告

    [POI2007]BIU-Offices 题意 给定\(n(\le 100000)\)个点\(m(\le 2000000)\)条边的无向图\(G\),求这个图\(G\)补图的连通块个数. 一开始想了半 ...

  10. SCWS中文分词,词典词性标注详解

    SCWS中文分词词典条目多达26万条之巨,在整理的时候已经把很多明显不对的标注或词条清理了 ---- 附北大词性标注版本 ----Ag 形语素 形容词性语素.形容词代码为a,语素代码g前面置以A. a ...