fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int bridge(int n, int m)
  5. {
  6. int cache[31][2] = {0};
  7. int h = 0;
  8.  
  9. while(true)
  10. {
  11. cache[h][0] = n;
  12. cache[h][1] = m;
  13. h++;
  14. if(m==1||n==1)
  15. break;
  16. m--;
  17. n--;
  18. }
  19.  
  20. for(int i=0;i<h;i++)
  21. {
  22. for(int j=0;j<h;j++)
  23. {
  24. if(cache[i][0] > cache[j][1])
  25. {
  26. if(cache[i][0]%cache[j][1] == 0)
  27. {
  28. cache[i][0] = cache[i][0]/cache[j][1];
  29. cache[j][1] = 1;
  30. }
  31. }
  32. else
  33. {
  34. if(cache[j][1]%cache[i][0] == 0)
  35. {
  36. cache[j][1] = cache[j][1]/cache[i][0];
  37. cache[i][0] = 1;
  38. }
  39. }
  40. }
  41. }
  42.  
  43. int g;
  44. if(n>m)
  45. g = 0;
  46. else
  47. g = 1;
  48. long long sum = 1;
  49. for(int i=0;i<h;i++)
  50. sum = sum*cache[i][g];
  51.  
  52. return sum;
  53. }
  54.  
  55. int main()
  56. {
  57. int t;
  58. scanf("%d",&t);
  59. int n, m;
  60. long long* out = new long long[t];
  61. for(int i=0;i<t;i++)
  62. {
  63. scanf("%d %d", &n, &m);
  64. out[i] = bridge(n, m);
  65. }
  66.  
  67. for(int i=0;i<t;i++)
  68. printf("%d\n",out[i]);
  69.  
  70. delete[] out;
  71. return 0;
  72. }
Success #stdin #stdout 0s 15232KB
stdin
1
14 20
stdout
232560