链接:http://codeforces.com/contest/483
Your friend has recently learned about coprime numbers. A pair of numbers {a,?b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a,?b) is coprime and the pair (b,?c) is coprime, then the pair (a,?c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a,?b,?c), for which the statement is false, and the numbers meet the condition l?≤?a?<?b?<?c?≤?r.
More specifically, you need to find three numbers (a,?b,?c), such that l?≤?a?<?b?<?c?≤?r, pairs (a,?b) and (b,?c) are coprime, and pair (a,?c) is not coprime.
The single line contains two positive space-separated integers l, r (1?≤?l?≤?r?≤?1018; r?-?l?≤?50).
Print three positive space-separated integers a, b, c ― three distinct numbers (a,?b,?c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number ⑴.
2 4
2 3 4
10 11
⑴
900000000000000009 900000000000000029
900000000000000009 900000000000000010 900000000000000021
In the first sample pair (2,?4) is not coprime and pairs (2,?3) and (3,?4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is ⑴.
In the third sample it is easy to see that numbers
900000000000000009 and 900000000000000021 are divisible by three.
简单构造:第1个数和第2个数互素,第2个数和第3个数互素,第1个数和第3个数不互素,明显找偶奇偶序列
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.
Your task is to find such minimum number v, that you can form presents using numbers from a set 1,?2,?...,?v. Of course you may choose not to present some numbers at all.
A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
The only line contains four positive integers cnt1, cnt2, x, y (1?≤?cnt1,?cnt2?<?109; cnt1?+?cnt2?≤?109; 2?≤?x?<?y?≤?3・104) ― the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.
Print a single integer ― the answer to the problem.
3 1 2 3
5
1 3 2 3
4
In the first sample you give the set of numbers {1,?3,?5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1,?3,?5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1,?2,?4} to the second friend. Thus, the answer to the problem is 4.
构造两个序列,第1个序列要有cnt1个数且其中不能有x的倍数,第2个序列要有cnt2个数且其中不能有y的倍数。要求求出这两个序列中的最大数的最小值。
如果答案是ans则ans+1也满足可以发现问题满足2分做法的条件,cnt1个数为num - num / x,及1到num中不包括x倍数的数的个数,同理
cnt2个数为num - num / y,还有1点要注意的是必须满足cnt1 + cnt2 <= num - num / (x * y)由于题目要求两个集合中的元素不同,又由于x,y必定互素,所以cnt1和cnt2的和必须小于1到num中不包括(x * y)倍数的数的个数,不然两个集合必定出现重复元素,然后2分num的值即可以得到终究答案。
Permutation p is an ordered set of integers p1,???p2,???...,???pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,???p2,???...,???pn.
Your task is to find such permutation p of length n, that the group of numbers |p1?-?p2|,?|p2?-?p3|,?...,?|pn?-?1?-?pn| has exactly k distinct elements.
The single line of the input contains two space-separated positive integers n, k (1?≤?k?<?n?≤?105).
Print n integers forming the permutation. If there are multiple answers, print any of them.
3 2
1 3 2
3 1
1 2 3
5 2
1 3 2 4 5
By |x| we denote the absolute value of number x.
1个包括n个数的数列,要求相邻两元素差的绝对值的数的个数为k,要求构造这样的数列。
简单的构造题,k--并变号判断便可
We'll call an array of n non-negative integers a[1],?a[2],?...,?a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1?≤?li?≤?ri?≤?n) meaning that value should be equal to qi.
Your task is to find any interesting array of n elements or state that such array doesn't exist.
Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal ― as "and".
The first line contains two integers n, m (1?≤?n?≤?105, 1?≤?m?≤?105) ― the number of elements in the array and the number of limits.
Each of the next m lines contains three integers li, ri, qi (1?≤?li?≤?ri?≤?n, 0?≤?qi?<?230) describing the i-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1],?a[2],?...,?a[n] (0?≤?a[i]?<?230) decribing the interesting array. If there are multiple answers, print any of them.
If the interesting array doesn't exist, print "NO" (without the quotes) in the single line.
3 1 1 3 3
YES 3 3 3
3 2 1 3 3 1 3 2
NO
题意如题,还是构造数列,线段树保护+判断