
gcd
w4149
无
展开
-
BZOJ 2818 Gcd (数论 欧拉)
【bzoj2818】Gcd2014年6月15日3,0930 Description给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对(x,y)有多少对.Input一个整数NOutput如题Sample Input4 Sample Output4 HINThint 对于样例(2,2),(2,4),(3,3),(4,2)1<=N<=10^7思路: 求1<=x,y<=N且Gcd(原创 2017-06-05 19:43:18 · 319 阅读 · 0 评论 -
BZOJ 3505 数三角形 (数论 组合数 gcd)
BZOJ 3505 数三角形 (数论 组合数)Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个。下图为4x4的网格上的一个三角形。注意三角形的三点不能共线。Input 输入一行,包含两个空格分隔的正整数m和n。Output输出一个正整数,为所求三角形数量。Sample Input 2 2Sample Output 76数据范围1<=m,n<=1000思路:原创 2017-07-05 16:51:40 · 585 阅读 · 0 评论 -
JZOJ 4714 公约数
JZOJ 4714【NOIP2016提高A组模拟8.19】公约数Description 给定一个正整数,在[1,n]的范围内,求出有多少个无序数对(a,b)满足gcd(a,b)=a xor b。 Input 输入共一行,一个正整数n。 Output 输出共一行,一个正整数表示答案。 Sample Input 3 Sample Output 1 解释:只有(2,3)满足要求 对于3原创 2017-09-10 15:58:55 · 398 阅读 · 0 评论 -
gcd 动态维护集合(Mobius)
10.3gcd思路: 用 f(i) 表示 gcd 为 i的数对个数, g(i) 表示 gcd 为 i的倍数的数对个数。那么 f(i)=Σμ(d)g(d) ,我们只需要维护 g(1)~g(max(xi)))。记 s(i) 表示 i的倍数个数,那么 g(i)=s(i)*(s(i)-1)/2,我们只需要在加入删除一个数时枚举它的因数修改s即可。 时间复杂度 O(msqrt(max(xi))%Doggu原创 2017-10-03 20:23:05 · 642 阅读 · 0 评论 -
pay 解方程 (exgcd)
10.19思路: exgcd解方程,等差数列求和#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#define LL long longusing namespace std;LL a, b, c;LL x, y;LL gcd(LL aa, LL bb, LL &x, LL &y){原创 2017-10-31 07:48:22 · 311 阅读 · 0 评论