HDOJ GCD 2588【欧拉函数】】的更多相关文章

GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3559    Accepted Submission(s): 1921 Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes writ…
Description 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 easily found by the Euclidean algorithm. Now Carp is consid…
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知识点:   欧拉函数.http://www.cnblogs.com/shentr/p/5317442.html 题解一: 当M==1时,显然答案为N. 当M!=1.  X是N的因子的倍数是 gcd(X,N)>1 && X<=N 的充要条件.so  先把N素因子分解, N=     …
题意:给出N,求所有满足i<j<=N的gcd(i,j)之和 这题去年做过一次... 设f(n)=gcd(1,n)+gcd(2,n)+......+gcd(n-1,n),那么answer=S[N]=f(1)+f(2)+...+f(N). 先求出每一个f(n). 令g(n,i)=[满足gcd(x,n)=i且x<N的x的数量],i是n的约数 那么f(n)=sigma[i*g(n,i)] (i即gcd的值,g(n,i)为数量) 又注意到gcd(x,n)=i -> gcd(x/i,n/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 Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1997    Accepted Submission(s): 772 Problem Description Do you have spent some time to think and try to solve those unsolved problem aft…
Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd(n−a,n)×gcd(n−b,n)=nk. Goffi wants to know the number of (a,b) satisfy the equality, if n and k are given and 1≤a,b≤n. Note: gcd(a,b) means greatest co…
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…
题目链接: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: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 76 Accepted Submission(s): 50   Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b…
题目链接:传送门 题目需求:Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.(2<=N<=1000000000, 1<=M<=N), 题目解析: 求(X,N),不用想要分解N的因子,分解方法如下,我一开始直接分解for(int i=2;i<=n/2;i++),这样的话如果n==10^9,那么直接超时,因为这点失误直接浪费了一中午 的时间,要这么分解for(in…
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 HINT 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 Source 湖北省队互测 若gcd(a,b)=素数p,则a=px,b=py且gcd(x,y)=1,这样,我们枚举小于n的素数p,对于每个素数p,只需求小于等于n/p的数中互质的数的对…
题目 传送门:QWQ 分析 仪仗队 呃,看到题后感觉很像上面的仪仗队. 仪仗队求的是$ gcd(a,b)=1 $ 本题求的是$ gcd(a,b)=m $ 其中m是质数 把 $ gcd(a,b)=1 $ 变形成 $ gcd(a,b)*m=m $ 然后在n的范围内枚举一下,使 $ gcd(a,b)*m <= n $ 再像仪仗队那样用欧拉函数搞一搞. 没了. 代码 #include <bits/stdc++.h> using namespace std; const int maxn=1e7+…
传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 9236  Solved: 4126[Submit][Status][Discuss] Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input…
GCD 描述 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 easily found by the Euclidean algorithm. Now Carp is considering…
网址:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 一道数论裸题,欧拉函数前缀和搞一下就行了. 小于n的gcd为p的无序数对,就是phi(1~n/p)的和,因为如果gcd(x,y)=p那么必有gcd(x/p,y/p)=1 转化成有序数对就可以把无序数对的个数*2-1(减1是因为有一个数对是(p,p)) 代码: ..]of longint; s:..]of int64; b:..]of boolean; n,m,i,j,k,t:longi…
I - Gcd HYSBZ - 2818 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input4 Sample Output4Hint hint 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 [分析]:欧拉函数计算互质个数 + 前缀和 + 次序不同算不同 + 去除1 [代码]: #include<bits/stdc++.h> using n…
bzoj[2818]Gcd Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 HINT hint对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 题解一(自己yy) phi[i]表示与x互质的数的个数 即gcd(x,y)=1 1<=y<x ∴对于x,y 若a为素数 则gcd(xa,…
题目: GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 125 Accepted Submission(s): 84   Problem Description Do you have spent some time to think and try to solve those unsolved problem afte…
题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入样例#1: 4 输出样例#1: 4 说明 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 上午用这道题考试(虽然略有区别不过差不多)qwq 用欧拉函数乱推... code:(ac代码) #include<cstdio> #define LL long long const int N=10…
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…
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…
GCDDescription 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4HINT hint 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 分析: 如果两个数字x,y,它们互质则 由gcd(x,y)=1 可知gcd(x*p[i],y*p[i])=p[i] 现在这个问题就变成了对于1~n的每个质数p[i],1~…
题目问[1,n]中与n的gcd大于等于m的数的个数. 好难想... 假设x满足条件,那么gcd(x,n)=d>=m,而x/d与n/d一定互质. 又x<=n,所以x/d<=n/d. 于是gcd(x,n)=d的x个数就等于小于n/d且与n/d互质的个数,即phi(n/d). 不同的d对应的x肯定会不重复,因为它们与n的gcd本来就不同.那么就是枚举最大公约数d,累加phi(n/d)就是答案了. #include<cstdio> #include<cstring> us…
http://www.lydsy.com/JudgeOnline/problem.php?id=2818 我很sb的丢了原来做的一题上去.. 其实这题可以更简单.. 设 $$f[i]=1+2 \times \phi (i) $$ 那么答案就是 $$\sum_{p是质数} f[n/p]$$ 就丢原来的题了...不写了.. #include <cstdio> #include <cstring> #include <cmath> #include <string>…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37161 题意:gcd(x, y) = 质数, 1 <= x, y <= n的对数 思路:显然gcd(x, y) = k, 1 <= x, y <= n的对数等于求(x, y) = 1, 1 <= x, y <= n/k的对数.所以,枚举每个质数p,然后求gcd(x, y) = 1, 1 <= x, y <= n/p的个数.那么…
2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 HINT hint 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 思路:gcd(x,y)…
GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2257    Accepted Submission(s): 908 Problem Description Do you have spent some time to think and try to solve those unsolved problem aft…
我们枚举所有gcd \(k\),求所有\(gcd=k\)的数对,记作\(f(k)\),那么\(ans=\sum_{i=1}^{n}(f(i)-1)*i\).为什么减1呢,观察题目,发现\(j=i+1\),所以自己与自己的数对是不算的. \(f(k)\)怎么求? 若\(a,b\)互质,则\(gcd(ak,bk)=k\). 我们枚举\(a,b\)中较大的那个,记作\(i\),那么另一个数就有\(φ(i)\)种可能,显然,\(1≤i≤n/k\),所以\(f(k)=\sum_{i=1}^{n/k}φ(i…
[bzoj2818]: Gcd 考虑素数p<=n gcd(xp,yp)=p 当 gcd(x,y)=1 xp,yp<=n满足条件 p对答案的贡献: 预处理前缀和就好了 /* http://www.cnblogs.com/karl07/ */ #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using…