题目: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…
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 the sequence B = [b1, b2, ..., bn] beautiful…
C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<cmath> using namespace std; ; int a[maxn]; int gcd(…
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1,可以执行一次操作使ai,ai+1变为ai - ai + 1, ai + ai + 1.求出使得gcd(a1,a2,....an)>1所需要的最小操作数. 解题思路:首先,要知道如果能够实现gcd(a1,a2,....an)>1,那么a1~an肯定都是偶数(0也是偶数),所以我们的目的就是用最少的操…
题目连接: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…
/* CF798 C. Mike and gcd problem http://codeforces.com/contest/798/problem/C 数论 贪心 题意:如果一个数列的gcd值大于1,则称之为美丽数列 给出数列a,可以将a_i 和 a_(i+1)换为其差和其和 如果可以变为美丽数列,输出YES并输出最少的变换次数 否则输出NO 思路: 如果变换a b a b -> a-b a+b -> -2b 2a 因此变换两个可以把a b乘以2 而若a b都是奇数,只需变换一次 所以每次先…
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 the sequence B = [b1, b2, ..., bn] beautiful if…
Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1…