hdu 1695 欧拉函数+容斥原理】的更多相关文章

GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15488    Accepted Submission(s): 5948 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x,…
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不会 就自己写了个容斥搞一下(才能维持现在的生活) //别人的题解https://blog.csdn.net/luyehao1/article/details/81672837 #include <iostream> #include <cstdio> #include <cstr…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, y)有多少组,不考虑顺序. 思路:a = c = 1简化了问题,原问题可以转化为在[1, b/k]和[1, d/k]这两个区间各取一个数,组成的数对是互质的数量,不考虑顺序.我们让d > b,我们枚举区间[1, d/k]的数i作为二元组的第二位,因为不考虑顺序我们考虑第一位的值时,只用考虑小于i的情…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4272    Accepted Submission(s): 1492 Problem 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)…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5064    Accepted Submission(s): 1818 Problem 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)…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/article/details/5787722 题意 a,b,c,d,k五个数,a与c可看做恒为1,求在a到b中选一个数x,c到d中选一个数y,使得gcd(x,y)等于k,求x和y有多少对. 首先可以想到选取的必是k的倍数,假设是x和y倍,则x和y一定是互质的在,那么就变成了求1到b/k和1到d/k的之…
Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 210    Accepted Submission(s): 57 Problem Description Lemon wants to be a hero since he was a child. Recently he is reading a book…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5235    Accepted Submission(s): 2225 Problem Description The Euler function phi is an important kind of function in number theo…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15810    Accepted Submission(s): 4914 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.   I…
Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1071    Accepted Submission(s): 323 Problem Description an = X*an-1 + Y and Y mod (X-1) = 0.Your task is to cal…
分析 考虑使用欧拉函数的计算公式化简原式,因为有: \[lcm(i_1,i_2,...,i_k)=p_1^{q_{1\ max}} \times p_2^{q_{2\ max}} \times ... \times p_m^{q_{m\ max}}\] 其实就是分解质因数,丢到那个式子里: \[\varphi(lcm(i_1,i_2,...,i_k))=\prod (p_i-1)p_i^{q_{i\ max}-1}\] 容易发现可以分开讨论每个质数,计算每个\(p_i^j\)在多少种\(i_1…
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<math.h> 6 using namespace std; 7 typedef long long ll;…
F - GCD Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1695 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 c…
裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int maxn=3000000+100; int phi[maxn]; void init() { for(int i=2;i<maxn;i++) phi[i]=i; for(int i=2;i<maxn;i++) i…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a <= b <= 100000, c=1, c <= d <= 100000, 0 <= k <= 100000) 思路:由于x与y的最大公约数为k,所以xx=x/k与yy=y/k一定互质.要从a/k和b/k之中选择互质的数,枚举1~b/k,当选择的yy小于等于a/k时,能够…
题目 给定两个区间[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…
http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = N,我们枚举 gcd(A, N) = g,那么gcd(B, N) = N / g.问题转化为统计满足 gcd(A, N) = g 的 A 的个数.这个答案就是 ɸ(N/g) 只要枚举 N 的 约数就可以了.答案是 Σɸ(N/g)*ɸ(g) g | N 暴力即可 #include <cstdio>…
题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数.φ(1)=1(唯一和1互质的数就是1本身). 因此含质因数最多的即为所求,打表求出前n个积,之后找到比自己小的最大积 大数打表 2015-07-27:到此一游 #include<cstdio> #include<iostream> #include<algorith…
GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2874    Accepted Submission(s): 1240 Problem Description Do you have spent some time to think and try to solve those unsolved problem af…
前置技能: <=i且与i互质的数的和是phi(i)*i/2 思路: 显然每个人的步数是gcd(a[i],m) 把m的所有因数预处理出来 1~m-1中的每个数 只会被gcd(m,i)筛掉一遍 //By SiriusRen #include <cstdio> #include <algorithm> using namespace std; ; typedef long long ll; ; int gcd(int a,int b){return b?gcd(b,a%b):a;}…
GCD  nyoj 1007 (欧拉函数+欧几里得) GCD 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6.(a,b) can be…
题目链接 题意 : 从[a,b]中找一个x,[c,d]中找一个y,要求GCD(x,y)= k.求满足这样条件的(x,y)的对数.(3,5)和(5,3)视为一组样例 . 思路 :要求满足GCD(x,y)=k的对数,则将b/k,d/k,然后求GCD(x,y)=1的对数即可.假设b/k >= d/k ;对于1到b/k中的某个数s,如果s<=d/k,则因为会有(x,y)和(y,x)这种会重复的情况,所以这时候的对数就是比s小的与s互质的数的个数,即s的欧拉函数.至于重复的情况是指:在d/k中可能有大于…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9046    Accepted Submission(s): 3351 Problem 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…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7357    Accepted Submission(s): 2698 Problem 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…
Problem 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 t…
输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和1到d/k 2个区间 如果第一个区间小于第二个区间 讲第二个区间分成2部分来做1-b/k 和 b/k+1-d/k 第一部分对于每一个数i 和他互质的数就是这个数的欧拉函数值 全部数的欧拉函数的和就是答案 第二部分能够用全部数减去不互质的数 对于一个数i 分解因子和他不互质的数包括他的若干个因子 这个…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4141    Accepted Submission(s): 1441 Problem 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)…
Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2181    Accepted Submission(s): 920 Problem Description Given a positive integer N, your task is to calculate the sum of the positiv…
Problem - 1286 用容斥原理做的代码: #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> using namespace std; ; int last[N]; void pre() { last[] = ; ; i < N; i++) { if (!last[i]) { for (int…
题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, b/k] $ 内 \(gcd(x, y) = 1\) 的(x, y)的对数. 假设a < b, 那么[1, a/k]这部分可以用欧拉函数算. 设 \(i\in (a/k, b/k]\), (a/k, b/k]这部分可以用容斥算, 用a/k减去[1, a/k]里面和i不互质的数的个数. 具体看代码.…