/* Problem 5--Billiards
   You could probably emulate the ball moving along the board and
   ricocheting when necessary, but it turns out that there's a nifty
   formula for it.  If a and b are relatively prime, the number of
   ricochets is a+b-1.  If a and b are not relatively prime, divide by
   their common factor first. */

import java.io.*;
import java.util.*;

public class prob5 {

 public static Scanner in=null;
 public static PrintWriter out=null;

 public static void main (String[] args) throws Exception {

  in = new Scanner (new File ("prob5.in"));
  out = new PrintWriter ("prob5.out");
  int a=0, b=0;
  int cs=1;
  while (true) {
   a = in.nextInt();
   b = in.nextInt();
   if (a==0 && b==0) break;
   int g = GCF(a,b);
   a/=g; b/=g; // Divide by the greatest common factor
   out.println ("Case "+(cs++)+": There will be "+
               (a+b-2)+" ricochet(s).");
  }
  in.close();
  out.close();
 }

 /* GCF computes and returns the greatest common factor of two integers
    using the traditional recursive algorithm. */
 public static int GCF (int a, int b) {

  return a%b==0?b:GCF(b,a%b);
 }
}
