Advertisement
silentkiler029

UVA-369

Jun 23rd, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. //  BISMILLAHIR-RAHMANIR-RAHIM
  2. /*
  3.  ____________________________________
  4. |                                    |
  5. |       SHANTO_SUST_SWE-19_029       |
  6. |___________________________________*/
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13.  
  14. #define debug 01
  15.  
  16. long long GCD(long long x, long long y)
  17. {
  18.     long long q, r;
  19.     while(r > 0){
  20.         r = x % y;
  21.         x = y;
  22.         y = r;
  23.     }
  24.     return x;
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30.      long long a, b, x;
  31.      long long i, j, k;
  32.      long long gcd, temp;
  33.  
  34.      while(1){
  35.         scanf("%lld %lld", &a, &b);
  36.         if(a + b == 0) break;
  37.         if(a == b){
  38.             printf("%lld things taken %lld at a time is 1 exactly.\n", a, b);
  39.             continue;
  40.         }
  41.  
  42.         x = b;
  43.         temp = a - b;
  44.         if(temp < b) b = temp;
  45.  
  46.         long long n[b], d[b];
  47.  
  48.         for(i = a, j = b, k = 0; k < b; j--, k++, i--){
  49.             n[k] = i, d[k] = j;
  50.         }
  51.  
  52.         //  i for d,    j for n
  53.  
  54.         for(i = 0; i < b; i++){
  55.             for(j = 0; j < b; j++){
  56.                 printf(" \b");
  57.                 gcd = GCD(n[j], d[i]);
  58.                 n[j] = n[j] / gcd;
  59.                 d[i] = d[i] / gcd;
  60.             }
  61.         }
  62.  
  63.         temp = 1;
  64.  
  65.         for(i = 0; i < b; i++) {
  66.             temp *= n[i];
  67.         }
  68.         printf("%lld things taken %lld at a time is %lld exactly.\n", a, x, temp);
  69.      }
  70.  
  71.  
  72.     return 0;
  73. }
  74. //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement