Codeforces Round #275 (Div. 2 ),

Source: Internet
Author: User

Codeforces Round #275 (Div. 2 ),

Link: http://codeforces.com/contest/483


A. CounterexampleTime limit per test1 secondmemory limit per test256 megabytes

Your friend has recently learned about coprime numbers. A pair of numbers {A, Bytes,B} Is called coprime if the maximum number that divides bothAAndBIs equal to one.

Your friend often comes up with different statements. He has recently supposed that if the pair (A, Bytes,B) Is coprime and the pair (B, Bytes,C) Is coprime, then the pair (A, Bytes,C) Is coprime.

You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (A, Bytes,B, Bytes,C), For which the statement is false, and the numbers meet the conditionLLimit ≤ limitALatency <latencyBLatency <latencyCLimit ≤ limitR.

More specifically, you need to find three numbers (A, Bytes,B, Bytes,C), Such thatLLimit ≤ limitALatency <latencyBLatency <latencyCLimit ≤ limitR, Pairs (A, Bytes,B) And (B, Bytes,C) Are coprime, and pair (A, Bytes,C) Is not coprime.

Input

The single line contains two positive space-separated integersL,R(1 digit ≤ DigitLLimit ≤ limitRLimit ≤ limit 1018;RAccept-Encoding-LLimit ≤ limit 50 ).

Output

Print three positive space-separated integersA,B,C-Three distinct numbers (A, Bytes,B, Bytes,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, latency 4) is not coprime and pairs (2, latency 3) and (3, latency 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 numbers9001_00000000009 and 900000000000000021 are divisible by three.


Simple structure: Number 1 and number 2 are mutually exclusive, number 2 and number 3 are mutually exclusive, and number 1 and number 3 are not mutually exclusive. It is clear that the parity sequence is searched.


#include <cstdio>#define ll long longll gcd(ll a, ll b) {    return b ? gcd(b, a % b) : a;  }int main(){    ll a, b;    ll ans[3] = {0};    scanf("%I64d %I64d", &a, &b);    if(b == a + 1)    {        printf("-1\n");        return 0;    }    if(a % 2 == 1)    {        ans[0] = a + 1;        ans[1] = a + 2;    }    else    {        ans[0] = a;        ans[1] = a + 1;       }    for(ll i = a + 2; i <= b; i++)    {        if(gcd(ans[1], i) == 1 && gcd(ans[0], i) != 1)        {            ans[2] = i;            break;        }    }    if(ans[2] == 0)    {        printf("-1\n");        return 0;    }    printf("%I64d %I64d %I64d\n", ans[0], ans[1], ans[2]);}




B. Friends and PresentsTime limit per test1 secondmemory limit per test256 megabytes

You have two friends. You want to present each of them several positive integers. You want to presentCnt1 numbers to the first friend andCnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number shocould be presented to both friends.

In addition, the first friend does not like the numbers that are divisible without remainder by prime numberX. The second one does not like the numbers that are divisible without remainder by prime numberY. Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum numberV, That you can form presents using numbers from a set1, clerk 2, clerk..., clerk ,...,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 integersCnt1,Cnt2,X,Y(1 digit ≤ DigitCnt1, bytes,Cnt2 bytes <limit 109;Cnt1 worker + workerCnt2 ≤ limit 109; 2 bytes ≤ bytesXLatency <latencyYLimit ≤ limit 3 · 104)-the numbers that are described in the statement. It is guaranteed that numbersX,YAre prime.

Output

Print a single integer-the answer to the problem.

Sample test (s) Input
3 1 2 3
Output
5
Input
1 3 2 3
Output
4
Note

In the first sample you give the set of numbers {1, numbers 3, numbers 5} to the first friend and the set of numbers {2} to the second friend. note that if you give set {1, interval 3, interval 5} to the first friend, then we cannot give any of the numbers1, 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, limit 2, limit 4} to the second friend. thus, the answer to the problem is4.


Construct two sequences. the first sequence must have the number of cnt1 and cannot have a multiple of x. The second sequence must have the number of cnt2 and cannot have a multiple of y. The minimum value of the maximum numbers in the two sequences must be obtained.


If the answer is ans, ans + 1 also meets the condition that the problem can be found to meet the binary practice. The number of cnt1 is num-num/x, and the numbers from 1 to num that do not contain multiples of x. Likewise

The number of cnt2 is num-num/y. Note that cnt1 + cnt2 <= num-num/(x * y) must be met because the question requires different elements in the two sets, and because x and y are mutually unique, the sum of cnt1 and cnt2 must be less than the number of multiples of 1 to num that do not contain (x * y, otherwise, the two sets must have repeated elements, and then the binary num value can get the final answer.


#include <cstdio>int cal(int a, int b){    return a - a / b;}int main(){    int cnt1, cnt2, x, y;    scanf("%d %d %d %d", &cnt1, &cnt2, &x, &y);    int l = 1, r = 2e9;             while(l < r)    {                      int mid = l + (r - l) / 2;        if(cnt1 <= cal(mid, x) && cnt2 <= cal(mid, y) && cnt1 + cnt2 <= cal(mid, x * y))            r = mid;        else            l = mid + 1;    }    printf("%d\n", r);  }



C. Diverse PermutationTime limit per test1 secondmemory limit per test256 megabytes

PermutationPIs an ordered set of integersP1, too many connections,P2, please wait..., please wait again ,...,PN, ConsistingNDistinct positive integers not largerN. We'll denoteNThe length of permutationP1, too many connections,P2, please wait..., please wait again ,...,PN.

Your task is to find such permutationPOf lengthN, That the group of numbers |P1 bytes-elapsed-P2 |, bytes |P2 bytes-elapsed-P3 |, large..., large |PNAccept-ranges 1 accept-ranges-PN| Has exactlyKDistinct elements.

Input

The single line of the input contains two space-separated positive integersN,K(1 digit ≤ DigitKLatency <latencyNLimit ≤ limit 105 ).

Output

PrintNIntegers 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 numberX.



For a series containing n numbers, k is required for the number of absolute values of the two adjacent elements, and such a series must be constructed.

Simply construct the question, k -- and change the number to determine


#include <cstdio>#include <cstring>int const MAX = 1e5 + 5;int a[MAX];int hash[MAX];int main(){    int n, k;    scanf("%d %d", &n, &k);    memset(hash, 0, sizeof(hash));    a[1] = 1;    hash[a[1]] = 1;    int cnt = 1;    for(int i = 2; i <= n; i++)    {        cnt++;        a[i] = a[i - 1] + k;        hash[a[i]] = 1;        if(k > 0)            k--;        else            k++;        k *= -1;        if(k == 0)            break;    }    for(int i = 1; i <= n; i++)        if(!hash[i])            a[++cnt] = i;    for(int i = 1; i < n; i++)        printf("%d ", a[i]);    printf("%d\n", a[n]);}




D. Interesting ArrayTime limit per test1 secondmemory limit per test256 megabytes

We'll call an arrayNNon-negative integersA[1], bytesA[2], middle..., middleA[N] Interesting, if it meetsMConstraints.I-Th ofMConstraints consists of three integersLI,RI,QI(1 digit ≤ DigitLILimit ≤ limitRILimit ≤ limitN) Meaning that value shoshould be equalQI.

Your task is to find any interesting arrayNElements or state that such array doesn't exist.

ExpressionX&YMeans the bitwise AND of numbersXAndY. In programming ages C ++, Java and Python this operation is represented as "&", in Pascal-as "and ".

Input

The first line contains two integersN,M(1 digit ≤ DigitNLimit ≤ limit 105, 1 limit ≤ limitMLimit ≤ limit 105)-the number of elements in the array and the number of limits.

Each of the nextMLines contains three integersLI,RI,QI(1 digit ≤ DigitLILimit ≤ limitRILimit ≤ limitN, 0 bytes ≤ bytesQILimit <limit 230) describingI-Th limit.

Output

If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line printNIntegersA[1], bytesA[2], middle..., middleA[N] (0 bytes ≤ bytesA[I] Limit <limit 230) decribing theinteresting 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.

Sample test (s) Input
3 11 3 3
Output
YES3 3 3
Input
3 21 3 31 3 2
Output
NO


The question is like a question, or a series is constructed, and the line segment tree is maintained + judged.


#include <cstdio>#include <cstring>#include <vector>using namespace std;int const MAX = 110000;struct Node{    int l, r;    int val;};Node tree[10 * MAX];Node a[MAX];vector<int> ans;void build(int step, int l, int r){    tree[step].l = l;    tree[step].r = r;    tree[step].val = 0;    if(l == r)        return;    int mid = (l + r) >> 1;    build(step << 1, l, mid);    build(((step << 1) + 1), mid+1, r);}void update(int step, int l, int r, int val){    if(tree[step].l == l && tree[step].r == r)    {        tree[step].val |= val;        return;    }    int mid = (tree[step].l + tree[step].r) >> 1;    if(r <= mid)        update(step << 1, l, r, val);    else if(l > mid)        update((step << 1) + 1, l, r, val);    else    {        update(step << 1, l, mid, val);        update((step << 1) + 1, mid+1, r, val);    }}int query(int step, int l, int r){    if(tree[step].l == l && tree[step].r == r)        return tree[step].val;    int mid = (tree[step].l + tree[step].r) >> 1;    if(r <= mid)        return query(step << 1, l, r);    if(l > mid)        return query((step << 1) + 1, l, r);    else        return query(step << 1, l, mid) & query((step << 1) + 1, mid+1, r);}void solve(int step){    if(step != 1)        tree[step].val |= tree[step >> 1].val;    if(tree[step].l == tree[step].r)    {        ans.push_back(tree[step].val);        return ;    }    solve(step << 1);    solve((step << 1) + 1);}int main(){    int n, m;    scanf("%d %d", &n, &m);    build(1, 1, n);    for(int i = 0; i < m; i++)    {        scanf("%d %d %d", &a[i].l, &a[i].r, &a[i].val);        update(1, a[i].l, a[i].r, a[i].val);    }    bool flag = true;    for(int i = 0; i < m; i++)    {        if(query(1, a[i].l, a[i].r) != a[i].val)        {            flag = false;            break;        }    }    solve(1);    if(flag)    {        printf("YES\n");        for(int i = 0; i < ans.size(); i++)            printf("%d%c",ans[i], i == n ? '\n' : ' ');        ans.clear();        printf("\n");    }    else        printf("NO\n");}






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.