1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10493 (Cats with or without hats)
*
* @author David Leib
* @author Julius Tschannerl
* @version 1.0, 03/23/2009
*
* Status : Accepted
* Runtime: 0.100
*/

//package Cats_Hats;

import java.io.*;
import java.util.*;

public class Main {

public static void main(String... args){

int n,m;

Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
while (n != 0)
{
System.out.printf("%d %d ",n, m);
if (n == 1 && m == 1)
System.out.printf("%s\n", "Multiple");
else if (n == 1 || !((m-n)%(n-1) == 0))
System.out.printf("%s\n", "Impossible");
else
System.out.printf("%d\n", (n*m-1)/(n-1));
n = sc.nextInt();
m = sc.nextInt();
}
System.exit(0);
}
}


2.

/**
* Angewandte Mathematik SS 09
10493 Cats Wit or Without Hats
* UVa Status: Accepted
* Run Time: 0.010
* Programming Language: ANSI C
29 April 2009
* @author Doina Logofatu logofatu@hm.edu
*/

#include <stdio.h>

int main(){

int n, m, c;

while(scanf("%d%d", &n, &m)==2 && n && m) {

printf("%d %d ", n, m);
if(n==1)
if(m==1) { printf("Multiple\n"); continue;}
else {printf("Impossible\n"); continue;}

c=m*n-1; n--;
if(c%n!=0) { printf("Impossible\n"); continue;}
else printf("%d\n", c/n);

}

return 0;

}