Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ program to find GCD of two numbers
- #include <iostream>
- using namespace std;
- // Recursive function to return gcd of a and b
- int gcdd(int a, int b)
- {
- if (b == 0)
- return a;
- return gcdd(b, a % b);
- }
- unsigned gcd_recursive(unsigned a, unsigned b)
- {
- if (b)
- return gcd_recursive(b, a % b);
- else
- return a;
- }
- // Driver program to test above function
- int main()
- {
- int a = 3, b = 1 , sum = 0 , gcdd ;
- int tc ;
- cin>> tc ;
- for(int i = 0 ; i<tc ; i++)
- {
- cin>> a ;
- for ( int y = 1 ; y<= a-1 ; y++)
- {
- gcdd = gcd_recursive(a, y ) ;
- if ( gcdd>1 )
- {
- sum = gcdd + sum ;
- }
- }
- cout<<sum<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement