• Source
    1. #include<bits/stdc++.h>
    2.  
    3. using namespace std;
    4.  
    5. int main()
    6. {
    7. int row,col,ans,a,b;
    8.  
    9. while(scanf("%d%d",&row,&col)==2)
    10. {
    11. if(row==0 && col==0)
    12. break;
    13.  
    14. a = row, b = col;
    15.  
    16. if(row>col)
    17. swap(row,col);
    18.  
    19. if(row==1)
    20. {
    21. printf("%d knights may be placed on a %d row %d column board.\n",col,a,b);
    22. }
    23. else if(row==2)
    24. {
    25. if(col%2)
    26. {
    27. ans = col+1;
    28. }
    29. else
    30. {
    31. ans = col+col%4;
    32. }
    33.  
    34. printf("%d knights may be placed on a %d row %d column board.\n",ans,a,b);
    35.  
    36. }
    37. else if((row&1) && (col&1))
    38. {
    39.  
    40. printf("%d knights may be placed on a %d row %d column board.\n",(row*col)/2+1,a,b);
    41.  
    42. }
    43. else
    44. {
    45.  
    46. printf("%d knights may be placed on a %d row %d column board.\n",(row*col)/2,a,b);
    47.  
    48. }
    49. }
    50.  
    51. return 0;
    52. }