Codeforces Round #325 (Div. 2) E. Alice, Bob, oranges and Apples

Source: Internet
Author: User

E. Alice, Bob, oranges and Apples

Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took a orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A ', or the letter 'B '. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'a ', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she ha D before. Thus the number of oranges and apples Alice had. If the card had written letter 'B ', then Bob does the same, that's, he gave Alice all the fruit that he had, and took From the bag the same set of fruit. After the last card to the removed, all of the fruit in the bag were over.

Know how many oranges and apples is in the bag at first. Your task is to find any sequence of cards that Alice and Bob could has played with.

Input

The first line of the input contains the integers, x, y (1≤ x, y ≤1018, xy > 1)-the number of oranges and apples that were initially in the bag.

Output

Print any sequence of cards that would meet the problem conditions as aCompressed string of characters 'A ' and 'b. That means that's need to replace the segments of identical consecutive characters by The number of repetitions of the characters and the actual character. For example, String aaabaabbb should being replaced by String 3a1b2a3b, but cannot be replaced By 2A1A1B2A3B or by< Span class= "Tex-font-style-tt" >3ab2a3b. See the samples for clarifications of the output format. The string that you print should consist of at Most 106  Characters. It is guaranteed this if the answer exists, its compressed representation exists, consisting of at Most 106 characters. If there is several possible answers, you is allowed to print any of them.

If the sequence of cards that meet the problem statement does isn't not exist, print a single word impossible.

Examplesinput
1 4
Output
3 b
Input
2 2
Output
Impossible
Input
3 2
Output
1a1b
Note

In the first sample, if the row contained three cards with letter 'B ', then Bob should give one apple to Alice three T IMEs. So, in the end of the game Alice have one orange and three apples, and Bob have one apple, in total it's one orange and fou R apples.

In second sample, there is no answer since one card isn't enough for game to finish, and both cards would produce at least Three apples or three oranges.

In the third sample, cards contain letters 'AB ', so after removing the first card Bob have one orange and one apple, an D after removal of second card Alice had both oranges and one apple. So, under total it is three oranges and both apples.

According to test instructions simulation, then you will find the process of GCD. And then do whatever it took.

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespacestd;#definell Long LongvoidSolve (ll A, ll b) {intTMP =0; if(b < a) TMP =0; ElseTMP =1; if(A <b) Swap (A, b);    ll C, D; C= A/b; ll ans= A/b;  while(a% b! =0) {C= A/b; D= a%b; if(c! =0) printf ("%i64d%c"C'A'+tmp); TMP^=1; A=b; b=D; Ans= A/b; //printf ("%i64d%i64d%i64d\n", A, B, c);} printf ("%i64d%c\n", ans-1,'A'+tmp);}intMain () {ll A, B;  while(Cin >> a >>b) {if(__GCD (A, b)! =1) puts ("Impossible"); ElseSolve (A, b); }}

Codeforces Round #325 (Div. 2) E. Alice, Bob, oranges and Apples

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.