Maison >interface Web >tutoriel HTML >Codeforces Round #275 (Div. 2)_html/css_WEB-ITnose
A. Counterexample
time limit per test 1 second
memory limit per test 256 megabytes
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?
More specifically, you need to find three numbers (a,?b,?c), such that l?≤?a?
Input
The single line contains two positive space-separated integers l, r (1?≤?l?≤?r?≤?1018; r?-?l?≤?50).
Output
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 -1.
Sample test(s)
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note
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 -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
题意很容易看懂,就不说了;
意解:简单点说就是一个简单暴力,数据看起来挺吓人的,其实三个for大胆搞,AC问题.
AC代码:
<span style="font-size:12px;">#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>using namespace std;typedef long long ll;const int M = 1e5 + 10;int e[M],t[M];ll gcd(ll a,ll b){ return b == 0 ? a : gcd(b,a % b);}int main(){ ll l,r; while(cin>>l>>r) { int vis = 0; for(ll a = l; a </cstdio></cstring></iostream></algorithm></span>
B. Friends and Presents
time limit per test 1 second
memory limit per test 256 megabytes
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.
Input
The only line contains four positive integers cnt1, cnt2, x, y (1?≤?cnt1,?cnt2?109; cnt1?+?cnt2?≤?109; 2?≤?x?
Output
Print a single integer ? the answer to the problem.
Sample test(s)
Input
3 1 2 3
Output
Input
1 3 2 3
Output
Note
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.
意解:二分答案加容斥原理,假设当前有n个坑,则放完c1或c2个坑,剩下的坑必须能够容纳n/x与n/y,否则不满足条件,此时要注意一个问题,但你把c1,c2填满后,要满足
至少剩余v / (x + y)多个坑.
AC代码:
<span style="font-size:12px;">#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>using namespace std;typedef long long ll;const int M = 1e5 + 10;int e[M],t[M];ll c1,c2,x,y;bool check(ll v){ if(v / x > v - c1 || v / y > v - c2) return false; if(v - c1 - c2 >c1>>c2>>x>>y) { ll L = 1; ll R = 1e9* 2; while(L > 1; if(check(mid)) R = mid; else L = mid + 1; } cout</cstdio></cstring></iostream></algorithm></span>
C. Diverse Permutation
time limit per test 1 second
memory limit per test 256 megabytes
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.
Input
The single line of the input contains two space-separated positive integers n, k (1?≤?k?
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Sample test(s)
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
意解:简单构造题.
AC代码:
#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int M = 1e5 + 10;int e[M],t[M];int main(){ int n,k,i = 1; cin>>n>>k; int a = 1,b = n; while(a = 0; i--) printf(i == 0? "%d\n" : "%d ",t[i]); else for(int i = 0; i <br> <br> <p></p> <br> <p></p> </cstdio></cstring></iostream></algorithm>