codeforces 664A Complicated GCD】的更多相关文章

水题..[a,b]区间数的最大公约数. a==b输出a 否则输出1 #include<cstdio> #include<cstring> #include<iostream> #include<queue> #include<stack> #include<cmath> #include<algorithm> using namespace std; #define clc(a,b) memset(a,b,sizeof(a…
题意真是七零八落,乱七八糟.盲目瞎写,水过就好? #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char s1[1005],s2[1005]; int main() { while(~scanf("%s%s", s1, s2)) { if(strcmp(s1, s2)==0) printf("%s\n", s1); el…
题目链接: A. Complicated GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that bot…
题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Greatest common divisor GCD(a, b) of two positive integers a and b is equ…
[题目链接] 点击打开链接 [算法] gcd(a,a+1) = 1 所以当a = b时,答案为a,否则为1 [代码] #include<bits/stdc++.h> using namespace std; string a,b; int main() { cin >> a >> b; if (a == b) cout<< a << endl; << endl; ; }…
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个数,满足一下条件: ①这k个数之和等于n ②每个满足①条件的数列有最大公约数q,输出q最大的数列. 思路: 我们只需要找出这个最大的q是什么.q满足: ①q是n的 公约数 ②n/q>=(1+2+3+···+k) ③q是满足①②中的最大的 只需要通过for(long long i=1;i<sqrt(…
C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2,…
http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一行中连续的某一部分 就是 这k个数 题意转化: 是否存在 一对i,j 满足gcd(i,j)=a1,gcd(i,j+1)=a2,…… gcd(i,j+k-1)=ak 直观上感觉: i要满足的必要条件是 i |  lcm(a1,a2……ak) j要满足的必要条件是 j= a1*k1,j+1=a2*k2……
原题链接:http://codeforces.com/problemset/problem/583/C 题意: 大概就是给你个gcd表,让你还原整个序列. 题解: 由$GCD(a,a)=a$,我们知道最大的那个数一定是原序列中的数,然后每次从集合中选取最大的数出来,和已经构造好的序列进行gcd,删除gcd出来的值即可. 代码: #include<iostream> #include<cstring> #include<map> #include<cstdio>…
[题目链接] https://codeforces.com/contest/1047/problem/C [算法] 首先求出n个数的最大公约数g , 将每个数除以g , 那么 , 问题就转化为在n个数中选出一个数集 , 使得这个数集中的数最大公约数不为1 , 最大化数集大小 预处理Ai范围内的质数 , 然后对于每个数分解质因数即可 时间复杂度 : O(NlogN + N log V) [代码] #include<bits/stdc++.h> using namespace std; ; ; i…
传送门:http://codeforces.com/contest/902/problem/D 本题是一个数学问题——多项式整除. 对于两个整数a.b,求最大公约数gcd(a,b)的辗转相除法的函数如下: int gcd(int a, int b) { ) return a; return gcd(b, a % b); } 一次辗转相除法将数对(a,b)转化成(b,a mod b),直至b=0. 对于多项式A(x),定义deg A(x)为多项式的次数.对于多项式A.B,定义多项式mod运算:若A…
题目链接 http://codeforces.com/problemset/problem/664/A 题意 给两个数,找出它们的最大公因子d,使得从a到b之间的数都可以整除d. 题解 结论: 当gcd(a, b) = 1,则gcd(a + b, a) = 1 反证法: 假设gcd(a + b, b) = k != 1; 则: b = k * r1 a + b =a +  k * r1 = k * R 两边同时除以k a / k + r1 = R 则要使相等,则a 必须整除k, 则 a = k…
题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这些数字增加的倍数x,使得序列变成${x,2x,3x...kx}$,然后再使最后一个数字变大满足要求就可以了,枚举的复杂度是根号$n$的. 要注意枚举倍数$x$的时候还要顺便枚举了$n/x$,然后${n*(n+1)/2}$这个东西是会爆long long的. #include<iostream> #…
You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to ai . Let's denote the function g(x,y) as the greatest common divisor of the numbers written on the vertices belonging to the simple…
Array GCD 最后的序列里肯定有a[1], a[1]-1, a[1]+1, a[n], a[n]-1, a[n]+1中的一个,枚举质因子, dp去check #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #de…
大意: 给定序列, 给定常数a,b, 两种操作, (1)任选一个长为$t$的子区间删除(不能全部删除), 花费t*a. (2)任选$t$个元素+1/-1, 花费t*b. 求使整个序列gcd>1的最少花费. 题目有个限制是不能全部删除, 所以最后一定剩余a[1]或a[n], 暴力枚举a[1]与a[n]的所有素因子即可. 这场div. 2题目感觉都挺简单的, 但实现起来各种出错...........各种细节还是没考虑好...... #include <iostream> #include &…
[题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数.          G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: 1. 令p为G中最大的数.在G中删除p,a中加入p.         2 . 对于a中的所有其他数(设为q),在G中删除2个gcd(p, q). 3. 若G为空则结束:否则回到(1). [代码] #include<bits/stdc++.h> using namespace std; #defin…
http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等于n ②严格递增 ②输出的这k个数的最大公约数q尽可能大. [思路] 因为是严格递增,所以sum[k]>=k(k+1)/2,而n<=1e10,所以k应该在1e5多一点. 可以找出最大的满足n<=1e10的k,给定的k超出这个直接输出-1. 然后接下来考虑怎么使最大公约数最大: 因为q肯定也是…
[链接] 我是链接,点我呀:) [题意] 给你一个数组A[]经过a[i][j] = gcd(A[i],A[j])的规则生成的二维数组 让你求出原数组A [题解] 我们假设原数组是A 然后让A数组满足A[i]<Ai+1 然后我们要先想到一个不等式 a[i][j]=gcd(A[i],A[j])<=A[min(i,j)] 而miin(i,j)<=n 则a[i][j]<=A[n] 所以a[i][j]里面的最大值就是A[n] 之后,我们把gcd(A[n],A[n])删掉 这样剩余的n*n-1…
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a…
题目大意:输入两个数 a,b,输出一个k使得lcm(a+k,b+k)尽可能的小,如果有多个K,输出最小的. 题解: 假设gcd(a+k,b+k)=z; 那么(a+k)%z=(b+k)%z=0. a%z+k%z=b%z+k%z:a%z=b%z:(a-b)%z=0; 也就是说,z一定是a-b的因子.a-b是已知的,枚举a-b的因子就好了. 也就是枚举z,因为(a+k)%z==0,如果让k最小,那么k=z-a%z. #include<iostream> #include<cstdio>…
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of…
题意:n个数的gcd是k,要你删掉最少的数使得删完后的数组的gcd > k 思路:先求出k,然后每个数除以k.然后找出出现次数最多的质因数即可. 代码: #include<cmath> #include<set> #include<map> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include <iostream…
一.先是一些整除的性质: •整除:若a=bk,其中a,b,k都是整数,则b整除a,记做b|a. •也称b是a的约数(因数),a是b的倍数 •显而易见的性质: •1整除任何数,任何数都整除0 •若a|b,a|c,则a|b+c, a|b-c •若a|b,则对任意整数c,a|bc •传递性:若a|b,b|c,则a|c 例1: •例题:[CF 762A]k-th divisor •求n的第k小的约数.如果不存在输出-1 •1 ≤ n ≤ 10^15, 1 ≤ k ≤ 10^9 分析:这道题显然不能用O(…
unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], b[105]; bool equal() { int lena = strlen (a); int lenb = strlen (b); if (lena != lenb) { return false; } for (int i=0; i<lena; ++i) { if (a[i] != b[i])…
第一个 写了两个比较简单的数论题目,就是整除理论的两个题目,第一个题目比较蠢,第二个稍微要动一点脑筋 Codeforces Round #347 (Div. 2) – A. Complicated GCD Codeforces Round #146 (Div. 1) – A. LCM Challenge 这两个都说明了两个小结论: 1.相邻两个整数互质.2.相邻两个奇数互质. 第二个就补了校赛的热身赛,那个lh的简单图论, 这个比较复杂,因为这个题目,我又学了一个新的lca的板子,我觉得这个新板…
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com/blog/entry/20692 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include &…
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C Description The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest c…
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers…
题目链接:https://codeforces.com/contest/1152/problem/C 题意:给定a,b(<1e9).求使得lcm(a+k,b+k)最小的k,若有多个k,求最小的k.(k>=0) 思路:昨晚打cf因为某些原因,沉不下心来看题,本来是个上分的好机会QAQ...所以吸取教训,下次状态好的时候再打比赛.    回到题目,首先给出gcd(a,b)=gcd(a,a-b),这个很显然,所以有gcd(a+k,b+k)=gcd(a+k,a-b).而lcm(a+k,b+k)=(a+…