daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jan 19th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int gcd_sum(int n)
  7. {
  8.     ll sum = 0;
  9.     for(int i = 1; i <= n; i++)
  10.         sum += __gcd(i,n); // built in function to calculate GCD
  11.     return sum;
  12. }
  13.  
  14. int main()
  15. {
  16.     ll n;
  17.     cin >> n;
  18.     cout << gcd_sum(n) << endl;
  19.  
  20.     return 0;
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top