当前位置:Gxlcms > html代码 > CodeforcesRound#275(Div.2)_html/css_WEB-ITnose

CodeforcesRound#275(Div.2)_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:2人阅读

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代码:

#include #include #include #include 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 <= r - 2&&!vis; a++)        {            for(ll b = a + 1; b <= r - 1 && !vis; b++)            {                for(ll c = b + 1; c <= r; c++)                {                    if(gcd(a,b) == 1 && gcd(b,c) == 1 && gcd(a,c) != 1)                    {                        vis = 1;                        cout<

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?

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代码:

#include #include #include #include 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 < v / (x * y)) return false;    return true;}int main(){    while(cin>>c1>>c2>>x>>y)    {        ll L = 1;        ll R = 1e9* 2;        while(L < R)        {            ll mid = (L + R) >> 1;            if(check(mid))                R = mid;            else L = mid + 1;        }        cout<

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 #include #include #include 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 < b)    {        e[i] = a++;        e[i + 1] = b--;        i += 2;    }    if(n & 1) e[i] = (n + 1) / 2;    if(k == n - 1)    {        for(int i = 1; i <= n; i++)            printf(i == n? "%d\n" : "%d ",e[i]);    }    else    {        int cn=0;        for(int i = 1; i <= k; i++)            printf("%d ",e[i]);        for(int i = k + 1; i <= n; i++)            t[cn++] = e[i];        sort(t,t + cn);        if(t[cn - 1] < e[k])            for(int i = cn - 1; i >= 0; i--)                printf(i == 0? "%d\n" : "%d ",t[i]);        else            for(int i = 0; i < cn; i++)                printf(i == cn - 1? "%d\n" : "%d ",t[i]);    }    return 0;}

人气教程排行