GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description Given integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest…
/** 题目:GCD 链接:https://vjudge.net/contest/178455#problem/E 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对(x,y)有多少对. 1<=N<=10^7 思路: 定义: f(n)表示gcd(x,y)==n的对数. F(n)表示n|gcd(x,y)的对数. 枚举n以内的素数p: f(p) = sigma(mu[d/p]*F(d)) (p|d) F(d) = (n/d)*(n/d); N/10*sqrt(N)复…
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),,)=,(,)=. (a,b) can be e…
开始系统的学习容斥原理!通常我们求1-n中与n互质的数的个数都是用欧拉函数! 但如果n比较大或者是求1-m中与n互质的数的个数等等问题,要想时间效率高的话还是用容斥原理!   本题是求[a,b]中与n互质的数的个数,可以转换成求[1,b]中与n互质的数个数减去[1,a-1]与n互质的数的个数. #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define LL lon…
题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cmath> using namespace std; typedef long long ll; template <class T> inline bool rd(T &ret)…
题目 给定两个区间[1, b], [1, d],统计数对的个数(x, y)满足: \(x \in [1, b]\), \(y \in [1, d]\) ; \(gcd(x, y) = k\) HDU1695 题解 我们观察式子\(gcd(x,y)=k\) 很显然,\(gcd(x/k, y/k) = 1\) 我们令b < d,令x<y(避免重复计数) 分类讨论. 1) y < b 可以看出答案就是\(\sum_{i \in [1, b]} \phi(i)\) 2)\(y \in [b, d…
Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're only required to output the total num…
2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit][Status][Discuss] Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数n,接下来n行每行五个整数,分别表示a.b.c.d.k Outp…
/** 题目:hdu1695 GCD 链接:http://acm.hdu.edu.cn/status.php 题意:对于给出的 n 个询问,每次求有多少个数对 (x,y) , 满足 a ≤ x ≤ b , c ≤ y ≤ d ,且 gcd(x,y) = k ,(5,7),(7,5)看做同一对, gcd(x,y) 函数为 x 和 y 的最大公约数. 本题默认:a = c = 1; 0 < a <= b <= 100,000, 0 < c <= d <= 100,000,…
一个点(x, y)的能量损失为 (gcd(x, y) - 1) * 2 + 1 = gcd(x, y) *  2 - 1. 设g(i)为 gcd(x, y) = i ( 1 <= x <= n, 1 <= y <= m ) 的数对(x, y)个数. 这个不好求, 考虑容斥, 设f(i) 为含有公因数 i 的数对(x, y)(1 <= x <= n, 1 <= y <= m)个数 , 显然f(i) = (n / i) * (m / i). 则 g(i) = f…