Advertisement
Jvsierra

MMC

Mar 27th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <locale.h>
  4.  
  5. int primo = 2;
  6.  
  7. void aumentaPrimo();
  8. int ePrimo(int n);
  9.  
  10. int main(){
  11.  
  12.   setlocale(LC_ALL, "Portuguese");
  13.  
  14.   int a, b, mmc = 1;
  15.  
  16.   scanf("%d %d", &a, &b);
  17.  
  18.   while(a > 1 || b > 1)
  19.   {
  20.     if(a % primo == 0 || b % primo == 0)
  21.     {
  22.         if(a % primo == 0)
  23.           a /= primo;
  24.  
  25.         if(b % primo == 0)
  26.             b /= primo;
  27.  
  28.         mmc = mmc * primo;
  29.     }
  30.     else
  31.         aumentaPrimo();
  32.   }
  33.  
  34.   printf("%d\n", mmc);
  35.  
  36.   getch();
  37. }
  38.  
  39. void aumentaPrimo(int n)
  40. {
  41.     int numero = primo + 1;
  42.  
  43.     while(ePrimo(numero) == 0)
  44.         numero++;
  45.  
  46.     primo = numero;
  47. }
  48.  
  49. int ePrimo(int n)
  50. {
  51.     int res, i, div = 0;
  52.  
  53.     for(i = 1; i <= n; i++)
  54.     {
  55.         if(n % i == 0)
  56.             div++;
  57.     }
  58.  
  59.     if(div <= 2)
  60.         res = 1;
  61.     else
  62.         res = 0;
  63.  
  64.     return res;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement