ACPrimer

UVA 11313 Gourmet Games

May 15th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int T,n,m,ans;
  5.     scanf("%d",&T);
  6.     while(T--)
  7.     {
  8.         scanf("%d%d",&n,&m);
  9.         ans=0;
  10.         while(n>=m)
  11.         {
  12.             ans+=n/m;
  13.             n=n/m+n%m;
  14.         }
  15.         if(n==1) printf("%d\n",ans);
  16.         else printf("cannot do this\n");
  17.     }
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment