Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int gcd_sum(int n)
- {
- ll sum = 0;
- for(int i = 1; i <= n; i++)
- sum += __gcd(i,n); // built in function to calculate GCD
- return sum;
- }
- int main()
- {
- ll n;
- cin >> n;
- cout << gcd_sum(n) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment