Advertisement
punidota

Untitled

Sep 19th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include"stdafx.h"
  2. #include"math.h"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. unsigned int gcd(unsigned int a, unsigned int b) {
  7.     unsigned int r;
  8.  
  9.     while (b != 0) {
  10.         r = a%b;
  11.         a = b;
  12.         b = r;
  13.     }
  14.  
  15.     return a;
  16. }
  17.  
  18. int main() {
  19.     unsigned int n, m;
  20.     unsigned int nm;
  21.     unsigned int lcm;
  22.     unsigned int cm;
  23.     setlocale(LC_CTYPE, "Rus");
  24.     n = rand();
  25.     m = rand();
  26.     nm = n*m;
  27.     lcm = n / gcd(n, m)*m;
  28.     cout << "Общие кратные, меньшие n*m = " << nm << ":" << endl;
  29.     for (cm = lcm; cm < nm; cm += lcm) {
  30.         cout << cm << " ";
  31.     }
  32.     cout << endl;
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement