Let’s assume that A and B together can complete the work in x days. So, the amount of work done by A and B together in one day is:

Work done by A and B together in one day = 1/x

As per the given information, A and B work together for 2 days, so the amount of work done by them in these two days is:

Work done by A and B together in 2 days = 2/x

Now, the remaining work is completed by A alone in 2 more days. Let’s assume that A alone can complete the work in y days. So, the amount of work done by A alone in one day is:

Work done by A alone in one day = 1/y

Since A worked alone for 2 more days, the total amount of work done by A in those 2 days is:

Total work done by A in 2 days = 2/y

Therefore, the total amount of work done in the first 4 days (2 days by A and B together and 2 days by A alone) is:

Total work done in first 4 days = 2/x + 2/y

As per the given information, the work is completed in 5 days in total. Therefore, the amount of work done by B alone in 3 days is:

Work done by B alone in 3 days = 1 – (2/x + 2/y)

Now, we know that B worked for only 2 days. Therefore, the total amount of work done by B in those 2 days is:

Total work done by B in 2 days = 2/x – Work done by A and B together in 2 days

Total work done by B in 2 days = 2/x – 2/x = 0

Since the work done by B alone in 3 days is equal to the remaining work after 4 days, we can say that:

Work done by B alone in 3 days = Work done by A alone in 2 days

Therefore, we can equate the above two expressions and get:

1 – (2/x + 2/y) = 2/y

Simplifying the above equation, we get:

2/x = 1/y

Multiplying both sides by yx, we get:

2 = xy

We are given that A and B together can complete the work in 3 days. Therefore:

1/x = Work done by A and B together in one day = 1/3

Substituting the above value of x in the equation 2 = xy, we get:

2 = y/3

Multiplying both sides by 3, we get:

y = 6

Therefore, B alone can complete the work in 6 days.