Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- using namespace std;
- int EuclidsAlgorithm(int m, int n);
- float Count(float a, int n);
- int EuclidsAlgorithm(int m, int n)
- {
- int r;
- while (n != 0)
- {
- r = m % n;
- m = n;
- n = r;
- }
- return m;
- }
- float Count(float a, int n)
- {
- float Sum = 1 / a;
- for (int i = 2; i < 2*n; i+=2)
- {
- Sum += 1 / pow(a, i);
- }
- return Sum;
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int m1, n1, m, n, result;
- float a;
- cout << "Введите два числа больших нуля" << endl;
- cout << "1 число: ";
- cin >> m;
- cout << "2 Число: ";
- cin >> n;
- m1 = m, n1 = n;
- result = EuclidsAlgorithm(m, n);
- cout << "НОД(" << m1 << "," << n1 << ") = " << result << endl;
- cout << "НОК(" << m1 << "," << n1 << ") = " << (m1*n1) / result << endl;
- cout << "a: ";
- cin >> a;
- cout << "n: ";
- cin >> n;
- cout << Count(a, n) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement