Advertisement
Mirbek

НОД

Jan 5th, 2022
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int gcd(int a, int b) {
  6.     if (!b) return a;
  7.     return gcd(b, a % b);
  8. }
  9.  
  10. int main(){
  11.     int n;
  12.  
  13.     while (cin >> n) {
  14.         if (n == 0) break;
  15.  
  16.         int G = 0;
  17.  
  18.         for (int i = 1; i < n; i++) {
  19.             for (int j = i + 1; j <= n; j++) {
  20.                 G = G + gcd(i, j);
  21.             }
  22.         }
  23.  
  24.         cout << G << endl;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement