artemgf

Закон Ома

Nov 7th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <algorithm>
  8. #include <string>
  9. #include <math.h>
  10. #include <vector>
  11. #include <cmath>
  12. #include <sstream>
  13. #include <queue>
  14.  
  15. using namespace std;
  16.  
  17. long long gcd05(long long a, long long b) {
  18.  
  19.     while (b) {
  20.         if (a > b) {
  21.             long long tmp = a;
  22.             a = b;
  23.             b = tmp;
  24.         }
  25.         b %= a;
  26.     }
  27.     return a;
  28. }
  29.  
  30. vector<long long>k;
  31. vector<long long> l;
  32. void O(long long n)
  33. {
  34.     int sc = 0;
  35.     for (int i = 1; i <= sqrt(n); i++)
  36.     {
  37.         if (n%i == 0)
  38.         {
  39.             l.push_back(i);
  40.             if(n/i!=i)
  41.             l.push_back(n / i);
  42.         }
  43.     }
  44. }
  45.  
  46. int main()
  47. {
  48.     long long n;
  49.     cin >> n;
  50.  
  51.     long long answ = n / 2;
  52.     O(n);
  53.     for (int i = 0; i < l.size(); i++)
  54.     {
  55.         for (int j = i + 1; j < l.size(); j++)
  56.         {
  57.             if (gcd05(l[i], l[j]) == 1)
  58.                 answ++;
  59.         }
  60.     }
  61.     if (n == 1)
  62.         cout << 1;
  63.     else
  64.         cout << answ+1;
  65.     system("pause");
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment