
GCD
九野的博客
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HDU 1788 Chinese remainder theorem again 中国剩余定理
题意:给定n,AA下面n个数m1,m2···mn则有n条方程res % m1 = m1-AAres % m2 = m2-AA问res的最小值直接上剩余定理,嘿嘿#include#include#include#include#include#include#include#includeusing namespace std;#define ll原创 2014-06-23 22:04:00 · 1431 阅读 · 0 评论 -
HDU 5381 The sum of gcd 莫队暴力
链接题解链接:http://www.cygmasot.com/index.php/2015/08/15/hdu_5381/题意:给定n长的序列下面n个数给出这个序列m个询问下面m行给出询问的区间。对于一个询问,输出这个区间内的任意子段的gcd 和。思路:因为一个数的gcd只会不变或下降,下降一次至少减半,下降至多32次,所以处理出每个数连续相同的gcd的区间。然后暴力跑莫队。#pragma comment(linker, "/STACK:1原创 2015-08-15 16:34:53 · 2574 阅读 · 0 评论 -
Codeforces 512B Fox And Jumping dp+gcd
题目链接:点击打开链接题意:给定n个数下面2行是n个数字和购买该数字的花费。使得购买的数字能通过加减获得任意一个正整数。问最小的花费是多少。(购买得到的数字可以多次使用)思路:首先是要获得任意的正整数,其实就是获得1就可以了。而获得1的话 只需要我们选的数的gcd = 1即可。设 有整数x,y,要使得x y能构造任意一个整数,充要条件就是gcd(x, y)=原创 2015-02-03 18:34:54 · 1732 阅读 · 0 评论 -
HDU 5072 Coprime 2014 Asia AnShan Regional Contest 容斥
#include #include #include #include #include using namespace std;/////template inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c'9')) c=getchar();原创 2014-10-27 09:32:05 · 1516 阅读 · 0 评论 -
Codeforces 475D CGCDSSQ 求序列中连续数字的GCD=K的对数
题目链接:点击打开链接#include #include #include #include #include #include using namespace std;typedef long long ll;template inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EO原创 2014-10-06 11:44:30 · 2350 阅读 · 0 评论 -
HDU 5042 GCD pair 预处理+二分 分段
点击打开链接#include #include #include #include #include #include using namespace std;typedef long long ll;ll gcd(ll x, ll y){ if(x>y)swap(x,y); while(x){ y%=x; swap(原创 2014-10-06 16:43:10 · 1788 阅读 · 0 评论 -
NWERC 2011 ABCDEH 题解
A:SPOJ NWERC11A A - Binomial coefficients题解:点击打开链接B: 点击打开链接 Bird tree从下到上发现是个gcd的过程(辗转相除#include #include #include using namespace std;int main() { int T; scanf("%d", &T);原创 2014-07-15 00:13:01 · 2399 阅读 · 0 评论 -
ZOJ Monthly, October 2010 ABEFI
ZOJ 3406Another Very Easy Task#include #include const int N = 100005;char s[N];int main() { bool f = 0; int size = 0; char ch; while(scanf("%c", &ch)!=EOF) { if( !(ch >= 'a' && c原创 2014-07-07 23:59:26 · 1426 阅读 · 0 评论 -
POJ 2891 Strange Way to Express Integers 中国剩余定理
裸题,上模版,,嘿嘿#include#include#include#include#include#include#include#include#includeusing namespace std;#define ll __int64ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b);}//求一组解(x,y原创 2014-06-23 22:30:39 · 1102 阅读 · 0 评论 -
HDU 3579 Hello Kiki 中国剩余定理(合并方程
题意:给定方程res % 14 = 5res % 57 = 56求res中国剩余定理裸题#include#include#include#include#include#include#include#includeusing namespace std;#define N 10005#define ll __int64ll gcd(ll a, ll原创 2014-06-23 21:02:55 · 1583 阅读 · 0 评论 -
Codeforces 338D GCD Table 中国剩余定理
题目链接:点击打开链接给定n*m的矩阵,[i,j]的点值为gcd(i,j)给定一个k长的序列,问是否能匹配上 矩阵的某一行的连续k个元素#include#include#include#include#include#include#include#includeusing namespace std;#define ll __int64ll gc原创 2014-06-22 23:12:49 · 1739 阅读 · 0 评论 -
exgcd求逆元模板
求x在模为mod时的逆元:exgcd(x,mod,x,y)求出后,第三个参数就是逆元。mod可以不为质数int exgcd(ll a,ll b,ll &x,ll &y){ if(a==0) { x=0;y=1; return b; } else { ll tx,ty;原创 2015-08-15 21:35:27 · 6049 阅读 · 0 评论