[gcd]Codeforces Common Divisors】的更多相关文章

Common Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Your task is to say the number of such positive integers xx such that x…
Common Divisors CodeForces - 182D 思路:用kmp求next数组的方法求出两个字符串的最小循环节长度(http://blog.csdn.net/acraz/article/details/47663477,http://www.cnblogs.com/chenxiwenruo/p/3546457.html),然后取出最小循环节,如果最小循环节不相同答案就是0,否则求出各个字符串含有的最小循环节的数量,求这两个数量的公因数个数(也就是最大公因数的因子个数)就是答案.…
B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个面积只能是给出的4*n个数中的最小值和最大值的乘积,如果这两个长度不凑成一个矩形,那么肯定全部矩形的面积会出现不一致的 代码: 1 //The idea was to use dichotomies to find that area, and then use that area to figur…
You are given an array aa consisting of nn integers. Your task is to say the number of such positive integers xx such that xx divides eachnumber from the array. In other words, you have to find the number of common divisors of all elements in the arr…
C.Common Divisors time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given an array…
http://codeforces.com/problemset/problem/182/D 题意:如果把字符串a重复m次可以得到字符串b,那么我们称字符串a为字符串b的一个因子,现在给定两个字符串S1和S2,求它们的公共因子个数. 思路: 先求最小循环节,如果最小循环节不同,那么肯定是没有公共因子的.如果相同的话,那就看循环节长度为1,2,3...是否可行. #include<iostream> #include<cstdio> #include<cstring> u…
题意: 给你n个数,让你找出来公因子有多少个.公因子:对于这n个数,都能被这个公因子整除 题解: 只需要找出来这n个数的最大公因子x,然后找出来有多少不同数能把x给整.(因为我们可以保证x可以把这n个数整除,又因为x是最大公因数,那么能把x整除的数肯定也可以把这n个数整除) 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #in…
题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n \leq 500 , 1 \leq a_i \leq 2\cdot 10^{18}\). 题解:考虑约数个数公式,可以发现对于任意的\(a_i\),有\(a_i=\left\{\begin{matrix}p^2\\ p^3\\ p^4\\ p_1\cdot p_2\end{matrix}\right…
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, ...…
题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers. But this problem is too simple for him, so he does not want to do it by…
448E - Divisors 思路: dfs.注意如果是1,直接返回,因为1的因子还是1. 因为x因子的因子还是x的因子,所以可以事先处理好x因子的因子在x因子中的位置. 不用这个方法也可以,用map映射vector保存因子的因子. 代码1: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem memset(a,b,sizeof(a)) ; vec…
C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.…
大意: 给定序列, 给定常数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 &…
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于10^5时直接-1就好: 我们可以构造出gcd为1的序列为 1,2,3,4……n-k+1: 然后一个个枚举n的因子p: 1*p,2*p,3*p……(n-k+1)*p: 当枚举的p使得序列不满足于严格递增时,结束,输出合法答案: 来,上代码: #include <cmath> #include &l…
一.题目描述 A common divisor for two positive numbers is a number which both numbers are divisible by. It's easy to calculate the greatest common divisor between tow numbers. But your teacher wants to give you a harder task, in this task you have to find…
https://atcoder.jp/contests/abc142/tasks/abc142_d 题意 求满足互素条件下的A和B的因子最多有几个 思路: 分解gcd(A,B)的质因子,再加上1: #include <iostream> #include<algorithm> #include<string> using namespace std; ; long long gcd(long long x,long long y) { )return x; return…
题目大意 如果把字符串a重复m次可以得到字符串b,那么我们称字符串a为字符串b的一个因子,现在给定两个字符串S1和S2,求它们的公共因子个数 题解 如果它们有公共因子,那么显然它们的最小公共因子肯定是相等的~~~,公因子就是字符串的最短循环节~~~所以我们先把两个最短循环节给求出来,并判断是否相同,如果相同的话就是它们的最小公因子,然后所有的最小公因子的倍数并且是S1和S2的公约数都是它们的公因子 代码: #include <iostream> #include <cstring>…
题目:Mike and gcd problem 题意:给一个序列a1到an ,如果gcd(a1,a2,...an)≠1,给一种操作,可以使ai和ai+1分别变为(ai+ai+1)和(ai-ai+1);问需要执行几次这个操作才能使得gcd(a1,a2,...an)>1. 分析: 1.首先,答案总是YES. 2,假设gcd(a1,a2,...an)=1,在一次对ai和ai+1的操作后新的gcd为d,则d满足:d|ai - ai + 1 and d|ai + ai + 1  d|2ai and d|2…
B. Bash's Big Day time limit per test:2 seconds memory limit per test:512 megabytes input:standard input output: standard output Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu'…
Let's call the following process a transformation of a sequence of length nn. If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary e…
codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不能既有逆序又有正序,例如12354)围成一个圆圈输出YES,否则输出NO,多组输入. 思路:以5为例有三种情况,12345:54321:32154(这种5在中间的可以归为一类):但他们都满足逐个数组中相邻的元素(首尾元素视为相邻)的差的绝对值最多只有1个是大于1的.也可以通过逆推题意假设他们已经围成…
Codeforces Round #117 (Div. 2) 代码 Codeforces Round #117 (Div. 2) A. Battlefield any trench in meters numerically does not exceed b. 这个条件意味着每次都是在蓄能开始时走向下一条线段,也就是说每条线段相当于花费了\(a+b\)的时间. bfs,用\(d_i\)表示到达线段i需要经过最少的线段条数,到达\(B\)的时候直接计算欧几里得距离. B. Vasya's Cal…
Description Let's call the following process a transformation of a sequence of length nn . If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove on…
There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations. Dima is sure that it'll be great to learn to solve the followi…
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator…
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Pr…
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 205; int q, n; int a[N], b[N], c[N]; int main() { ios::sync_with_stdio(false);…
思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, 5, 4] 变成 [1, 2, 3, 4, 5]; 思路 我的方法是差分,假如成立,相邻两个数的差的绝对值要么是1要么是n-1. #include<iostream> #include<cstdio> #include<algorithm> #include<cmat…
A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针正好是 1-n的顺序 思路:水题,把数组开两倍,或者标记当前位置都可以 #include<bits/stdc++.h> #define maxn 100005 #define mod 1000000007 using namespace std; typedef long long ll; int…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5869 Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting.…